我試圖模擬一些軟件,我需要用戶能夠在字段中輸入一些文本,然後根據該文本將它們引導到另一個頁面。我已經創建了下面的代碼,但它似乎沒有工作。我使用的是IE 7,它似乎刷新了頁面,它不會真正轉到新的位置。任何人都明白爲什使用jQuery 1.4.4分鐘 *基於評論 *仍然沒有工作基於文本字段值在輸入密鑰上重定向用戶
<form id="TEST"><input type="text" id="command" tabindex="1"></form>
<script type="text/javascript">
$(document).ready(function() {
$('#command').keypress(function(e) {
if (e.which === 13) {
if ($('#command').value === "AI") {
window.location = "http://www.mozilla.org";
}
if ($('#command').value === "BRI") {
window.location = "http://www.google.com";
}
}
});
});
</script>
也許你錯過了引號?你在哪裏定義「AI」和「BRI」變量? – sdleihssirhc