我有一个 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/
关于Javascript : function statement requires a name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28072426/