2017-02-03 93 views
2

我使用這個JS來嘗試設置輸入框中沒有文本,當用戶點擊清除按鈕如何更改輸入框的文本?

// This code is not inside of the clearText function 
var input = document.getElementById("input"); 

// this code is inside of the clearText function 
input.innerHTML = ""; 

這裏是我使用的輸入框和清除按鈕的HTML:

<input id="input" type="text"> 

<button onclick="clearText()">Clear Factors</button> 

我該做什麼錯了?

回答

3

嘗試一下input.value = "";輸入與像element這樣的元素稍有不同,其中innerHTML會像您期望的那樣工作。 http://www.w3schools.com/jsref/prop_text_value.asp

+1

好的!我現在就試試。 @fredriksapps – Tler

+1

它的工作原理!謝謝:D – Tler

+1

@fredrikapps我曾計劃過這樣做,大聲笑!我不得不等待12分鐘,直到我可以 – Tler