我希望能够在input
元素中设置value
属性的内容,但尚未成功完成此操作。使用.html()不工作的jQuery设置输入值属性
HTML:
<div class='photo-info'>
Photo Name : <span class='photo-name'><?php echo $title; ?></span>
<span class='title-edit'><a href='#'>Edit</a></span>
</div>
的jQuery:
// show editable area for title
$('.title-edit').on('click', function() {
var $titleElm = $(this).prev();
var text = $titleElm.text();
$titleElm.html("<input type='text'>").val('tom');
})
结果:
https://jsfiddle.net/fh7t9qwd/1/
我建议只是做以下$ titleElm.html( “”); – cmw2379