Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery文本html操作,在大量文本中查找出现的字符,然后更改它';s颜色_Javascript_Jquery_Html_String_Text - Fatal编程技术网

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