jquery – 如何在表中的行周围添加边框

我有一张桌子,每排都有字段.如果字段为空,我希望特定的行周围有红色边框.

<table cellpadding="3" cellspacing="5" >
<tr>
<td class="cellformatting"><label>first name*</label></td>
<td class="cellformatting"><input id="fname" type="text" class="required searchfields" />
</td>
</tr>
<tr>
 <td class="cellformatting"><label>last name*</label></td>
<td class="cellformatting"><input id="lname" type="text" class="searchfields" /></td>
</tr>
</table>

我想要脚本,如果假设姓氏是空的,它应该在显示姓氏的表的特定行周围添加一些css.

解决方法

这样的事情怎么样:

$(function(){

    checkBorder();

    $("table tr input").change(function(){
       checkBorder(); 
    });

});
function checkBorder(){
 $("table tr").each(function(){
    if ($(this).find("input").val() == ""){
       $(this).attr("class","border");   
    }
});   
}
​

http://jsfiddle.net/kh6q8/

这是一个没有“规范化CSS”的版本,但必须删除单元格间距:

http://jsfiddle.net/kh6q8/2/

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...