Javascript jQuery文本html操作,在大量文本中查找出现的字符,然后更改它';s颜色
我得到了这个Javascript jQuery文本html操作,在大量文本中查找出现的字符,然后更改它';s颜色,javascript,jquery,html,string,text,Javascript,Jquery,Html,String,Text,我得到了这个HTML <div id="oops_menuHldrs" style=" border-top:5px solid #ccc; position:absolute; width:100%; background:#343434; bottom:0px; left:auto;"> <div style="position:absolute; background:#343434; border-radius:10px
HTML
<div id="oops_menuHldrs"
style=" border-top:5px solid #ccc; position:absolute; width:100%; background:#343434; bottom:0px; left:auto;">
<div style="position:absolute; background:#343434; border-radius:10px; border:1px solid #CCC; right:0px; top:-20px; padding:5px;">
<table id="opps_menu_links" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><span><a href="../?abt=us">About us</a> black_text | black_text</span></td>
<td><span><a href="../?ourA=gent">Our Agents</a> black_text | black_text</span></td>
<td><span><a href="../contact=us">Contact us.</a> black_text | black_text </span></td>
</tr>
</table>
</div>
这会将所有内容转换为单个红色|
当然,如果没有jQuery
,这将很容易,只需使用span
为每个|
穿上衣服即可。。。但是,如何使用jQuery
以尽可能少的代码实现呢
有什么帮助吗?如下更改脚本
$('opps#u menu_links').html($('opps#u menu_links').html()。替换(/\\\/g,'.');
除了您忘记在正则表达式中放置全局匹配参数“g”
之外,所有操作都是正确的:
.replace(/\|/g,
//-----------^----place this
最终代码应为:
$('#opps_menu_links').html(
$('#opps_menu_links').text()
.replace(/\|/g,"<span style='color:#f00;'>|</span>"));
//---------------^----------place here
$('opps#u menu_links').html(
$(“#opps_菜单_链接”).text()
.替换(/\\\;/g,“\”);
//---------------^----------放在这里
.replace(/\|/g,
//-----------^----place this
$('#opps_menu_links').html(
$('#opps_menu_links').text()
.replace(/\|/g,"<span style='color:#f00;'>|</span>"));
//---------------^----------place here