admin管理员组文章数量:1402783
I have the following code of jquery that gets the first word of the label.
var val = $(this).find('label').html(); // The value must be Graphic Designer
$(this).find('label').replaceWith('<input type=text value='+val+'); // The input's value is Graphic
Here is the jsfiddle
I have the following code of jquery that gets the first word of the label.
var val = $(this).find('label').html(); // The value must be Graphic Designer
$(this).find('label').replaceWith('<input type=text value='+val+'); // The input's value is Graphic
Here is the jsfiddle
Share Improve this question edited Jun 16, 2014 at 12:36 chridam 104k26 gold badges243 silver badges241 bronze badges asked Jun 16, 2014 at 12:33 deviloperdeviloper 7,24010 gold badges50 silver badges79 bronze badges 02 Answers
Reset to default 8You forgot the html close tag character >
and it's string ender '
, and you should add "
in your input. Should be:
'<input type=text size=40 value="'+val+'" />'
^ ^
http://jsfiddle/vgNS8/
Build the input with jQuery instead:
$("#editInfoBtn").click(function(){
$(".inline-update").each(function(){
var val = $(this).find('label').html(),
// build the element here
$input = $('<input>',{attr:{'type':'text','size':40},val:val});
// insert it here
$(this).find('label').replaceWith($input);
});
});
Chances are you're running into problem with the quotes.
本文标签: javascriptWhy html() and text() selects only the first wordStack Overflow
版权声明:本文标题:javascript - Why .html() and .text() selects only the first word? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744324690a2600666.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论