(我使用jquery中的before()函数向div层追加一个新的<p>元素。
$('#AddParagraphButton').click(function() {
$('#TheLayer').before('<p contentEditable='true'>Some text...</p>');
});这里,我将keypress函数设置为插入<br>标记。
$('p').keypress(function(e){
if(e.which == 13){
e.preventDefault();
document.execCommand('insertHTML', false, '<br/>');
}
});这很好(br标记插入),直到调用追加函数并添加一个新的<p>。如何使livequery解除键压事件并再次绑定?
编辑: <p>标记具有contentEditable属性。我这么做是因为<br>标记是用div包装的,我只想要<br>标记
发布于 2010-12-30 21:10:31
您考虑过使用内置的live()功能吗?
描述:现在和将来,对于所有匹配当前选择器的元素,都会为事件附加一个处理程序。
$('p').live("keypress", function(e){
e.preventDefault();
if(e.which == 13){
document.execCommand('insertHTML', false, '<br/>');
}
});https://stackoverflow.com/questions/4566285
复制相似问题