我的代码不起作用,你能帮我吗?我希望将 class="s7" 的标签名称“p”更改为“h1”
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".s7").replaceWith($('<h1>' + $(this).html() + '</h1>');
});
</script>
问题是您将所有元素与类相匹配s7
,但是您需要对它们进行一一处理,以便将其内容复制到新元素中。在您当前的代码中,this
总是document
,不是当前元素。
您可以使用each() http://api.jquery.com/each/迭代匹配的元素:
$(".s7").each(function() {
var $this = $(this);
$this.replaceWith($("<h1>" + $this.html() + "</h1>"));
});
或者可能:
$(".s7").each(function() {
$("<h1>" + $(this).html() + "</h1>").replaceAll(this);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)