我有以下jquery代码来获取标签的第一个单词。
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
以下是jsfiddle
答案 0 :(得分:8)
您忘记了html关闭标记字符>
及其字符串ender '
,您应该在输入中添加"
。应该是:
'<input type=text size=40 value="'+val+'" />'
^ ^
答案 1 :(得分:7)
使用jQuery构建输入:
$("#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);
});
});
你可能会遇到引号问题。