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 "
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,""")
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.
精彩评论