JQUERY:如何在DIV中删除除BR和IMG之外的所有HTML标记
当我在里面写作时
在DIV Contenteditable中删除除和
之外的所有HTML标签
到目前为止我正在使用
$('#aa').text()
但它删除了一切
我试着用它
$('#aa').keydown(function(e) { var datasts=$("#aa").html(); datasts=datasts.substr(datasts.length - 1); if (e.keyCode === 13) { document.execCommand('insertHTML', false, 'enter'); return false; } }); document.getElementById("aa").addEventListener("input", function() { var a=$("#aa").text(); $("#aa").html(a.replace('enter', '
')); }, false);
但结果不是最大的
这是我改变的代码
<button onclick="$('#aa').html('');"> aa $('#aa').keydown(function(e) { var datasts=$("#aa").html(); datasts=datasts.substr(datasts.length - 1); if (e.keyCode === 13) { document.execCommand('insertHTML', false, '
'); return false; } }); document.getElementById("aa").addEventListener("input", function() { $("#aa").children().not("br, img").remove(); }, false);
我想在写作位置删除html标签。 复制html时,会自动删除html标签
尝试这个,如果那个孩子不是br或img,那将删除#aa的任何孩子
$("#aa").children().not("br, img").remove()