日期:2014-05-16 浏览次数:20424 次
<table id="td">
<tr>
<th id=“"sec">第一头</th>
<th>第二头</th>
</tr>
<tr>
<td>
<input type="text" name="usr">
</td>
<td>
<input type="button" value="check" onclick="cheng();">
</td>
</tr>
</table>
<html>
<head>
<title>aaaa</title>
</head>
<body>
<script type="text/javascript">
function cheng(obj)
{
var input = getFirstChild(get_previoussibling(obj.parentNode));
if(input.value=="")
document.getElementById("sec").style.color = "#ff0000";
}
function get_previoussibling(n)
{
var x=n.previousSibling;
if(x == null) return null;
while (x && x.nodeType!=1)
{
x=x.previousSibling;
}
return x;
}
function getFirstChild(obj){
for (i=0; i<obj.childNodes.length; i++){
if (obj.childNodes[i].nodeType==1)
return obj.childNodes[i];
else
continue;
}
}
</script>
<table id="td">
<tr>
<th id="sec">第一头</th>
<th>第二头</th>
</tr>
<tr>
<td>
<input type="text" name="usr">
</td>
<td>
<input type="button" value="check" onclick="cheng(this);">
</td>
</tr>
</table>
</body>
</html>