<head>
<meta charset="UTF-8">
<title>获取标签附近的元素以及在标签中查找子元素</title>
</head>
<body>
<form action="">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
<td></td>
</tr>
<hr>
<tr>
<td>密码:</td>
<td><input type="text" name="password"></td>
<td></td>
</tr>
</table>
</form>
</body>
<script src="js/jquery-1.8.3.js"></script>
<script>
$("[name='username']").on("focus",function () {
$("[name='username']").parent().next().html(":用户名不能为空").css("color","red");
}).on("blur",function () {
/*$("[name='username']").parent().next()[0].innerHTML="";*/
$("[name='username']").parent().next().html("您输入的用户名是:"+$("[name='username']").val())
})
</script>