工作数据:
<div>this is a div with 12H-912</div>
<table>
<tr><td>7H-9123123</td></tr>
<tr><td>08A-912234</td></tr>
<tr><td>08132A-912234</td></tr>
</table>
Javascript:
$('body').ready(function(){
$('div').each(function(){
var html = $(this).html();
if (html.match(/[0-9]{2}[A-H]{1}-[0-9]+/g)) {
$(this).html(html.replace(/([0-9]{2}[A-H]{1}-[0-9]+)/g, '"$1"'));
}
});
// easier and safer when in a td (alone)
$('td').each(function(){
var html = $(this).html();
if (html.match(/^[0-9]{2}[A-H]{1}-[0-9]+$/g)) {
$(this).html(html.replace(/([0-9]{2}[A-H]{1}-[0-9]+)/g, '"$1"'));
}
});
});
输出:
this is a div with "12H-912"
7H-9123123
"08A-912234"
08132A-912234
我会让你算出超链接。你可以在这里摆弄它:http: //jsfiddle.net/fCJJb/