我想对.change()
价值变化做出反应。在这种情况下,必须更新另一个(隐藏的)字段。
<input type="text" name="n1"><br>
<input type="text" name="n2"><br>
<input type="text" name="n3"><br>
<input type="hidden" name="h1"><br>
<script>
$("input[type='text']").change( function() {
try {
$temp = $(this).next("input[type='hidden']");
} catch (e) { // just for testing
alert("not found "+e);
}
try {
$temp = $(this).next("input[name='h1']");
} catch (e) { { // just for testing
alert("not found "+e);
}
$temp.val("hidden");
alert("Temp is a "+$temp);
alert("Temp has following value:"+$temp.val());
})
</script>
用于测试的演示:http: //jsfiddle.net/22C2n/1209/
这个说法
$temp = $(this).next("input[type='hidden']");
导致“未定义”,或者更好: $temp 是 $object[] 而不是(作为方面) $object[ input name='h1']
问题出在哪里?