如何使用jquery查找和替换HTML标记属性?
我想使用Jquery查找并替换标记属性或更改内联css 例如:如何使用jquery查找和替换HTML标记属性?,jquery,css,inline,Jquery,Css,Inline,我想使用Jquery查找并替换标记属性或更改内联css 例如: 我想找到内联样式,并在页面加载时将其替换为。在dom ready上,您可以针对所有span元素,如 jQuery(function($){ $('span[style]').removeAttr('style') }) 如果要将所有具有样式属性的元素作为目标 $('[style]').removeAttr('style') Jquery中的Simple只需使用以下内容 $("span").removeAttr("sty
我想找到内联样式
,并在页面加载时将其替换为
。在dom ready上,您可以针对所有span元素,如
jQuery(function($){
$('span[style]').removeAttr('style')
})
如果要将所有具有样式属性的元素作为目标
$('[style]').removeAttr('style')
Jquery中的Simple只需使用以下内容
$("span").removeAttr("style");
$("span").addClass("line");
试试这个:
$(document).ready(function(){
$('span[style]')
.removeAttr('style')
.addClass('line');
});
如果需要精确匹配下划线规则,可以添加约束。只要替换这个:
$('span[style]')
为此:
$('span[style="text-decoration: underline;"]')
为了完整起见,这里有一个例子
这应该可以参见
Html
<p>My mother has <span style="text-decoration: underline;">blue</span> eyes and my father has <span style="text-decoration: underline;">dark green</span> eyes.</p><button onclick="btncheck();">Check</button>
查看此演示:
您可以这样做,根据需要更新css样式
这样,您仍然可以使用其他样式并仅删除所需的css样式
JQUERY
HTML
测试内容
测试内容
<p>My mother has <span style="text-decoration: underline;">blue</span> eyes and my father has <span style="text-decoration: underline;">dark green</span> eyes.</p><button onclick="btncheck();">Check</button>
$(document).ready(function(){
$("button").click(function(){
$('span[style="text-decoration: underline;"]')
.removeAttr('style')
.addClass('line');
});
});
$(document).ready(function(){
$('span').each(function(){
if($(this).css('text-decoration') === 'underline'){
$(this).css({'text-decoration':''});
$(this).addClass('line');
}
});
});
<span style="text-decoration: underline;">Test Content</span><br /><br />
<span style="text-decoration: underline;">Test Content</span>