我有一张桌子,每排都有字段.如果字段为空,我希望特定的行周围有红色边框.
<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>
Run Code Online (Sandbox Code Playgroud)
我想要脚本,如果假设姓氏是空的,它应该在显示姓氏的表的特定行周围添加一些css.
这样的事情怎么样:
$(function(){
checkBorder();
$("table tr input").change(function(){
checkBorder();
});
});
function checkBorder(){
$("table tr").each(function(){
if ($(this).find("input").val() == ""){
$(this).attr("class", "border");
}
});
}
?
Run Code Online (Sandbox Code Playgroud)
这是一个没有"规范化CSS"的版本,但cell-spacing必须删除:
| 归档时间: |
|
| 查看次数: |
5565 次 |
| 最近记录: |