当页面加载过内联css时,我正在尝试实现removeAttr。这在一定程度上起了作用,但并不是万能的。
下面是一个演示问题JSfiddle的https://jsfiddle.net/argilmour/efmxoL0h/
$(document).ready(function(){
$('.text_default').children().removeAttr('style');
});发布于 2015-05-29 14:59:38
我认为你需要改变JQuery选择器。将您的JavaScript更改为:
$('.text_default *').removeAttr('style');根据您的JSFiddle,您忘记添加JQuery。
在HTML代码中添加以下内容:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>在JSFiddle中,将库添加到网页左侧的列中。
发布于 2015-05-29 14:59:03
您可以尝试这样做,children不匹配.text_default的所有后代。否则,find("*")将匹配所有的子级及其后代。
$('.text_default').find("*").removeAttr('style'); 发布于 2015-05-29 14:59:22
.children()只对元素的直接子元素起作用。如果要从所有后代中删除style属性,请说:
$(document).ready(function(){
$('.text_default').find('*').removeAttr('style');
});或者只是:
$(document).ready(function(){
$('.text_default *').removeAttr('style');
});
$(document).ready(function() {
$('.text_default *').removeAttr('style');
});.text_default {
font-size: 14px;
line-height: 16px;
font-family: verdana;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<tr class="layout_default">
<td class="layout_default" align="left" valign="middle">
<div class="repcontent">
<div class="text_default">
<p dir="ltr" style="font-family: Verdana, Arial; font-size: 11px; text-align: justify; line-height: 1; margin-top: 5pt; margin-bottom: 0pt;"><span style="font-size: 13px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">Special conditions apply to the collection and holding of "sensitive" data. In this case you must obtain the </span>
<span
style="font-size: 13px; font-family: Arial; font-style: italic; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">specific</span><span style="font-size: 13px; font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;"> consent of the student/learner (ideally in writing). You may encounter this when gathering information before arranging work placements, outdoor activities or when taking photographs you intend to use later, perhaps for publicity or publication purposes. "Sensitive Data" has a special definition under the Data Protection Act and covers:</span>
</p>
<ul>
<li><span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">race or ethnic origin </span>
</li>
<li><span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">political belief religious or other beliefs </span>
</li>
<li><span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">trade union membership (or otherwise) </span>
</li>
<li><span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">sexual life </span>
</li>
<li><span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">physical or mental health or condition (including pregnancy, learning or physical disability) </span>
</li>
<li><span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;">actual or alleged criminal records or activities </span> </li>
</ul>
</div>
</div>
</td>
</tr>
https://stackoverflow.com/questions/30532753
复制相似问题