[英]clear input fields onsubmit
能否請您仔細查看此資源,因為提交后我沒有任何結果。 謝謝。
<script type="text/JavaScript">
function reset() {
document.city.citysearch.value = "";
return true;
}
</script>
<form name='city' action='airport.php' method='post'
target='result' onsubmit='return reset()'
>
<input name="citysearch" type="text"
placeholder="Name of the city" size="18">
<input type="hidden" name="submit" value="search">
似乎有一個名為“ submit”的隱藏字段,這是非常糟糕的做法。 如果您要重置表單字段,請嘗試使用重置按鈕( http://www.w3schools.com/tags/att_button_type.asp ),而無需使用JS:
<form name='city' action='airport.php' method='post' target='result' onsubmit='return reset()'>
<input name="citysearch" type="text" placeholder="Name of the city" size="18">
<input type="hidden" name="search" value="search">
<button type="reset">Reset</button>
<button type="submit">Submit</button>
</form>
更新 :聽起來您想在提交后重設字段。 做這個服務器端。 嘗試返回需要使用屬性value =“”重置的字段。
您的問題用詞不好,但是根據標題,我認為您在清除Javascript中的citysearch輸入時遇到問題嗎? 如果是這種情況,請嘗試使用JS類似的方法:
var x = document.getElementsByName("citysearch")
x[0].value = ''
而是這樣做:
var button = document.getElementById('clear');
button.addEventListener('click', empty);
function empty(){
var input = document.getElementById('text');
input.value='';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.