我有一个html表,其中的行看起来像:
<tr>
<td><input type="checkbox" name="check[]" value="265"></td>
<td>265</td>
<td>NO MATCH</td>
<td>NO MATCH</td>
<td>No</td>
<td>0</td>
<td>f79a8316891</td>
</tr>
我正在尝试构建一个jQuery函数,该函数仅在以“ NO”开头时才突出显示单元格。到目前为止,我有:
$( "td" ).hover( function() {
var contents = $( this ).html() ;
if (contents.match("^NO")) {
function() {
$( this ).append( $( "<span> ***</span>" ) );
}, function() {
$( this ).find( "span:last" ).remove();
}
}
});
但标题出现错误。我究竟做错了什么?
您将函数放在错误的位置。尝试这样的事情:
$( "td" ).hover( function() {
var contents = $( this ).html() ;
if (contents.match("^NO")) {
$( this ).append( $( "<span> ***</span>" ) );
}
}, function() {
$( this ).find( "span:last" ).remove();
});
jQuery悬停函数使用两个函数作为参数,第一个用于“鼠标移过”,第二个用于“鼠标移出”。您只需将这些函数放在原始代码中的错误位置即可。有关悬停的更多信息,请参见http://api.jquery.com/hover/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句