关于jQuery选取tr的第二个td里面input元素val问题 请问我的代码写的对不对。。。
<scripttype="text/javascript">$(function(){$("#btn").click(function(){if($("student_t...
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
if($("student_table:input").eq(1).attr("name").val() == "")
{
alert("编号不能为空");
$("student_table:input").eq(1).attr("name").focus();
}
});
});
</script>
</head>
<body>
<div>
<div class="top">
<div id="picture"><img src="resource/providers.png" width="47" height="47"></div>
<div id="head"><h1>添加学生</h1></div>
</div>
<div id="table">
<form action="AddStudent" method="post" id="student_table">
<table border="0">
<tr>
<td>学生编号</td>
<td><input type="text" name="student.stunum" id="student_id">*</td>
</tr>
<tr>
<td>学生姓名</td>
<td><input type="text" name="student.stuname"></td>
</tr>
<tr>
<td>性别</td>
<td><select name="student.sex">
<option value="男">男</option>
<option value="女">女</option>
</select></td>
</tr>
<tr>
<td>所属学院</td>
<td><input type="text" name="student.college" ></td>
</tr>
<tr>
<td>所属学院编号</td>
<td><input type="text" name="student.collegenum"></td>
</tr>
<tr>
<td>所属专业</td>
<td><input type="text" name="student.college" ></td>
</tr>
<tr>
<td>所属专业编号</td>
<td><input type="text" name="student.majornum"></td>
</tr>
<tr>
<td>年级</td>
<td><input type="text" name="student.stugrade"></td>
</tr>
<tr>
<td>班级</td>
<td><input type="text" name="student.stuclass"></td>
</tr>
<tr>
<td>联系方式</td>
<td><input type="text" name="student.stutel"></td>
</tr>
<tr>
<td>个人简介</td>
<td><textarea name="student.stuintro" class="textarea"></textarea></td>
</tr>
</table>
<button type="submit" id="btn">添加</button>
</form>
</div>
</div> 展开
$(function(){
$("#btn").click(function(){
if($("student_table:input").eq(1).attr("name").val() == "")
{
alert("编号不能为空");
$("student_table:input").eq(1).attr("name").focus();
}
});
});
</script>
</head>
<body>
<div>
<div class="top">
<div id="picture"><img src="resource/providers.png" width="47" height="47"></div>
<div id="head"><h1>添加学生</h1></div>
</div>
<div id="table">
<form action="AddStudent" method="post" id="student_table">
<table border="0">
<tr>
<td>学生编号</td>
<td><input type="text" name="student.stunum" id="student_id">*</td>
</tr>
<tr>
<td>学生姓名</td>
<td><input type="text" name="student.stuname"></td>
</tr>
<tr>
<td>性别</td>
<td><select name="student.sex">
<option value="男">男</option>
<option value="女">女</option>
</select></td>
</tr>
<tr>
<td>所属学院</td>
<td><input type="text" name="student.college" ></td>
</tr>
<tr>
<td>所属学院编号</td>
<td><input type="text" name="student.collegenum"></td>
</tr>
<tr>
<td>所属专业</td>
<td><input type="text" name="student.college" ></td>
</tr>
<tr>
<td>所属专业编号</td>
<td><input type="text" name="student.majornum"></td>
</tr>
<tr>
<td>年级</td>
<td><input type="text" name="student.stugrade"></td>
</tr>
<tr>
<td>班级</td>
<td><input type="text" name="student.stuclass"></td>
</tr>
<tr>
<td>联系方式</td>
<td><input type="text" name="student.stutel"></td>
</tr>
<tr>
<td>个人简介</td>
<td><textarea name="student.stuintro" class="textarea"></textarea></td>
</tr>
</table>
<button type="submit" id="btn">添加</button>
</form>
</div>
</div> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询