我想我在某处遗漏了一行,或者需要更改一行。我尝试了各种 /g 方法,但我认为 exec 在这里杀死了我,也许我错过了一些简单的小补充,或者我写它的方式有缺陷。看到很多线程在循环执行时提到了一个,但这似乎是无限循环,因为我在替换中包含了匹配项。
这是我到目前为止得到的代码
var system_url="http://somesite.com/";
$('.words').mouseover(function(){
var re=new RegExp("[A-Z][A-Z][A-Z]-[0-9]{5}");
var m=re.exec($(this).html());
if (m == null) {
re=new RegExp("[0-9]{5}");
m=re.exec($(this).html());
if (m == null) {}else{
if ($(this).html().match("</a>")) {}else{
tx=$(this).html().replace(m,"<a href='"+system_url+m+"' target='_blank' title='Ticket: "+m+"'>"+m+"</a>");
$(this).html(tx);
}
}
}else{
if ($(this).html().match("</a>")) {}else{
tx=$(this).html().replace(m,"<a href='"+system_url+m+"' target='_blank' title='Ticket: "+m+"'>"+m+"</a>");
$(this).html(tx);
}
}
});
一些 HTML 类:
<span class='words'>The quick brown ZAD-14034 jumped over the EAD-14534</span>
<span class='words'>The 13034 brown fox jumped over the ZEN-12274</span>