我在表單中爲我的網站創建了一個AJAX日誌;不過,我遇到了一些我認爲是jQuery中的bug。
代碼示例:
<!DOCTYPE html>
<html>
<head>
<title>Log In</title>
</head>
<body>
<div class="errors"></div>
<input type="username" placeholder="username">
<input type="password" placeholder="password">
<input type="submit" value="Log In">
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script>
$('input[type=submit]').click(function(){
$(".errors").load(window.location.protocol + "//" + window.location.host + "?username=" + $("input[type=username]").val() + "&password=" + $("input[type=password]").val());
return false;
});
</script>
</html>
我知道一個事實,即它不是一個服務器端的問題。 $("input[type=username]").val()
的返回值是undefined
,而$("input[type=password]").val()
的返回值是輸入的值。 謝謝大家! :)
之前宣稱 「錯誤」,請確保您的測試用例是有效的第一。 [HTML Validator](http://validator.w3.org/)會告訴你你的錯誤。 – 2012-07-16 19:26:15
人們認爲,從網上收穫插件使他們jQuery * ninjas * – Alexander 2012-07-16 19:48:31