jQuery 动态 HTML 属性覆盖脚本
jQuery dynamic HTML attributes overwriting script
几天来我一直在努力使用 jQuery 尝试编写一个脚本来替换从论坛聊天框动态创建的 span 样式颜色。
这两个元素都包裹在一个 td
元素中 class="chat"
和一个 style="color:green"
的跨度像这样
<td class="chat"><span style="color:darkgreen;">test</span></td>
例如,我尝试编写的脚本(遗憾的是没有成功);
$(".chat:contains('darkgreen')").css("color", "rgb(255, 111, 7)");
$(".chat:contains('darkgreen')").css("font-weight", "bold");
$(".chat:contains('darkgreen')").css("text-shadow", "bold");
$(".chat:contains('darkgreen')").css("text-shadow", "rgb(0, 0, 0) 1px 1px 1px");
$(".chat:contains('darkgreen')").css("text-shadow", "rgb(255, 111, 7) 1px 0px 6px");
我也尝试过将 class "chat" 更改为其他一些 class,例如 td
、chat
但 none他们中的任何一种都可以工作,任何想法我怎样才能使它与 jQuery 一起工作,即使在聊天框生成新的 td
& class 以使用我的 CSS?
您可以通过
访问它
$(".chat>span[style='color:darkgreen;']")
.css({
"color":"rgb(255, 111, 7)",
"font-weight": "bold",
"text-shadow": "bold",
"text-shadow": "rgb(0, 0, 0) 1px 1px 1px",
"text-shadow": "rgb(255, 111, 7) 1px 0px 6px"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="chat"><span style="color:darkgreen;">test</span></td>
</tr>
</table>
几天来我一直在努力使用 jQuery 尝试编写一个脚本来替换从论坛聊天框动态创建的 span 样式颜色。
这两个元素都包裹在一个 td
元素中 class="chat"
和一个 style="color:green"
的跨度像这样
<td class="chat"><span style="color:darkgreen;">test</span></td>
例如,我尝试编写的脚本(遗憾的是没有成功);
$(".chat:contains('darkgreen')").css("color", "rgb(255, 111, 7)");
$(".chat:contains('darkgreen')").css("font-weight", "bold");
$(".chat:contains('darkgreen')").css("text-shadow", "bold");
$(".chat:contains('darkgreen')").css("text-shadow", "rgb(0, 0, 0) 1px 1px 1px");
$(".chat:contains('darkgreen')").css("text-shadow", "rgb(255, 111, 7) 1px 0px 6px");
我也尝试过将 class "chat" 更改为其他一些 class,例如 td
、chat
但 none他们中的任何一种都可以工作,任何想法我怎样才能使它与 jQuery 一起工作,即使在聊天框生成新的 td
& class 以使用我的 CSS?
您可以通过
访问它$(".chat>span[style='color:darkgreen;']")
.css({
"color":"rgb(255, 111, 7)",
"font-weight": "bold",
"text-shadow": "bold",
"text-shadow": "rgb(0, 0, 0) 1px 1px 1px",
"text-shadow": "rgb(255, 111, 7) 1px 0px 6px"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="chat"><span style="color:darkgreen;">test</span></td>
</tr>
</table>