我想使用jQuery檢索輸入值。使用jQuery檢索輸入值
這裏的HTML:
<input type="text" name="a" id="a" />
<input type="button" name="b" id="b" value="Click here"/>
這裏是jQuery的:
$(document).ready(function() {
var normal=$('#a').val();
$('#b').on("click", function() {
alert(normal);
});
});
由於某些原因,alert(normal);
不工作而alert($('#a').val());
一樣。爲什麼?是不是normal
和$('#a').val();
保持相同的值?
如果你想要的jsfiddle:http://jsfiddle.net/L2uX4/20/
感謝
行,因爲它不是動態....它不會重新綁定,你得到的價值在那個時間點是你所擁有的,直到你再次覆蓋變量。 – epascarello