Javascript removeAttr内部字符串html
我想从字符串html中删除attr。 我有这个密码Javascript removeAttr内部字符串html,javascript,jquery,Javascript,Jquery,我想从字符串html中删除attr。 我有这个密码 var htm = result.Html; $(htm, 'div').each(function () { $(this).removeAttr('ondragover'); $(this).removeAttr('ondragleave'); $(this).removeAttr('ondrop
var htm = result.Html;
$(htm, 'div').each(function () {
$(this).removeAttr('ondragover');
$(this).removeAttr('ondragleave');
$(this).removeAttr('ondrop');
});
$('#divLayout').html(htm);
但问题是字符串仍然是原始的
注意:result.Html等于:
<div class="updiv containertwo" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
<div id="fchoise" class="detdiv containertwo">
<div id="df4a6783-beb2-2cdf-0b1d-611c4d7b195f" class="div1" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
</div>
<div class="updiv containertwo" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
<div id="ghchoise" class="containertwo detdiv">
<div id="932e29b5-b6fe-97f5-d3dc-21768291ec90" class="lefts" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
<div id="cfac8011-0e4e-3eba-aaaa-ac36b58b1512" class="rights" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
</div>
<div class="downdiv containertwo" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
<div id="thchoise" class="containertwo detdiv">
<div id="3b8b92b3-45f9-54b2-b01a-60b60f65f175" class="lefts" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
<div id="c73e2dc9-9980-774b-5d50-c35336d8201d" class="rights" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
</div>
<div class="downdiv containertwo" ondrop="drop(event)" ondragleave="dragleave(event)" ondragover="allowDrop(event)"></div>
更改jQuery对象不会修改原始字符串,因此需要
var htm = result.Html;
var $tmp = $('<div />', {
html: htm
});
$tmp.find('div[ondragover]').removeAttr('ondragover');
$tmp.find('div[ondragleave]').removeAttr('ondragleave');
$tmp.find('div[ondrop]').removeAttr('ondrop');
$('#divLayout').html($tmp.html());
var htm=result.Html;
变量$tmp=$(''{
html:htm
});
$tmp.find('div[ondragover')).removeAttr('ondragover');
$tmp.find('div[ondragleef')).removeAttr('ondragleef');
$tmp.find('div[ondrop]')).removeAttr('ondrop');
$('#divLayout').html($tmp.html());
演示:这非常简单,请参见:
var$html=$('',{html:result.html});
$html.find('div').removeAttr('ondragover ondragleef ondrop');
$('#divLayout').html($html.html());
查看它的实际操作:同时告诉我们您正在尝试做什么……这似乎是您解决某些问题的一种方法,但问题是什么。您可以将代码放在上面吗?result.Html是什么?它存储了什么?我从result.html中的数据库获取html,然后我需要从结果中删除属性并附加到另一个div