开发者

Not displaying after quote mark

After I run my script, the input field essentially looks like this:

<input ty开发者_运维技巧pe="text" value="How do you " />

Even if I slash the quotes or change them to &quot; it still doesn't work.

Any suggestions?

$('input').html(function() {
    var dataVal = 'How do you "feel" about that?';

    return '<input type="text" value="' + dataVal + '" />';
});


Add this after the dataVal definition.

dataVal = dataVal.replace(/"/g,"&quot;")

It replaces all " characters by the HTML entity of a quotation mark, fixing your code.

Currently, your parsed HTML looks like this:
<input type="text" value="How do you "feel" about that?" />, which is translated to
<input type="text" value="How do you " />.


You may want this instead:

$('input').val(function() {
    var dataVal = 'How do you "feel" about that?';
    return dataVal;
});

or just

$('input').val('How do you "feel" about that?');

html is for defining the contained html of an element, whereas val is for defining the value of an input field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜