我正在通過文本框打開url的腳本,下面是我迄今爲止正在處理的代碼及其失敗的代碼。從文本框中打開url
<form id="main" name="main">
<input type="text" name="inputtext" id="inputtext" placeholder="type here"/>
<input type="submit" value="submit" onClick="test();">
</form>
<script>
function test() {
$("main").submit(function(e) {
if($('inputtext').val() == 'google'){
// alert('Input can not be left blank');
window.location.href = "https://www.google.com/";
}
if($('inputtext').val() == 'yahoo'){
// alert('Input can not be left blank');
window.location.href = "https://www.yahoo.com/";
}
if($('inputtext').val() == ''){
alert('Input can not be left blank');
}
});
}
</script>
請諮詢我,如果我錯了工作路徑上還是歡迎使用javascript
也許這個鏈接會幫助你https://stackoverflow.com/questions/32486489/redirect-to -a-url-based-user-input-to-an-autocomplete-field –
我投票將其作爲拼寫錯誤關閉,因爲你錯過了一個'#'來選擇在jQuery –