我有一個文本框和一個搜索按鈕。的onsubmit window.location的工作不
Onclicking
搜索按鈕window.location
正在工作。
但按回車鍵window.location
不起作用。
我已經閱讀提交作品時,輸入鍵被按下,但爲什麼在這裏按回車鍵window.location不起作用。
這裏是我的代碼:
<div>
<form id="form">
<input id="bar"
style="height:26px; left:29%; top:270px; position:absolute;
border:1px solid #CCC;
font:20px arial,sans-serif;
background-color:transparent; z-index:6; outline:none;
width:500px;"
spellcheck="true";
onfocus="";
type="text" value="" title="Search" autocomplete="on" maxlength="2048" />
</form>
<input id="searchbutton"
style="height:30px; top:330px; position:absolute; left:33%; background-image:-webkit-linear-gradient(top,#f8f8f8,#f1f1f1);
-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.1);
background-color:#f8f8f8;
border:1px solid #c6c6c6;
box-shadow:0 1px 1px rgba(0,0,0,0.1);
color:#333;
border-radius:2px;"
type="button" value="Google Search"/>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$("#searchbutton").click(function() {
var q;
q = $("#bar").val();
window.location = "https://www.google.com/search?q=" + q;
});
$('#form').submit(function() {
var q;
q = $("#bar").val();
window.location = "https://www.google.com/search?q=" + q;
});
});
</script>
爲什麼不改變文本輸入類型來提交? – chepe263
window.location.href = –
@ A.Wolff:爲什麼有人會在按鈕上按回車鍵? 我在這裏說的是文本框。 –