HTML部分
<form onsubmit="return search()" style="white-space: nowrap;">
<input type="text" autocomplete="off" id="search_input" placeholder="必应搜索...">
<button onclick="return search()">搜索</button>
</form>
其中,style="white-space: nowrap;"
使按钮不换行,与输入框保持在同一行上。
JavaScript部分
function search() {
if (document.getElementById("search_input").value != "") {
window.location.href = "https://cn.bing.com/search?q=" + document.getElementById("search_input").value;
document.getElementById("search_input").value = "";
}
return false;
}
By MeltIce.