我有一张桌子,每排都有字段.如果字段为空,我希望特定的行周围有红色边框.
<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>
解决方法
这样的事情怎么样:
$(function(){ checkBorder(); $("table tr input").change(function(){ checkBorder(); }); }); function checkBorder(){ $("table tr").each(function(){ if ($(this).find("input").val() == ""){ $(this).attr("class","border"); } }); }