如何动态创建div可编辑 [英] How to make div editable which is created dynamically
本文介绍了如何动态创建div可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望 div 可编辑,动态。这也是可拖动 div。
I want to make div editable which is created dynamically. Which is also draggable div .
这就是我尝试过的事情
1)$("#divid").attr('contentEditable','true');
2)$("#divid").live("click",function(){
$(this).click('contentEditable',true);
});
3)$("#divid").click('contentEditable',true);
但以上都不起作用。
任何想法如何让它工作!
but none of the above working. Any idea how to make it working!
提前致谢!
推荐答案
因为你有一个动态创建的div,所以使用 .on()
处理程序和 .prop()
:
Since you are having a dynamically created div use .on()
handler for it and .prop()
:
$(document).on("click", "#divid", function(){
$(this).prop('contentEditable',true);
});
查找小提琴: http://jsfiddle.net/SEvDe/
这篇关于如何动态创建div可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文