我正在處理一個簡單的ASP.NET項目。我有HTML和一個JS文件。我試圖將表單輸入的值發送到JS文件,但由於某種原因它似乎被打破。 我的形式看起來像:爲什麼我的HTML表單不會將數據發送到我的JS文件?
<div class="set-the-clock">
<form name="settheclock">
<span>Hours: </span><input type="text" id="fhours" value=""><br>
<span>Minutes: </span><input type="text" id="fminutes" value=""><br>
<span>Seconds: </span><input type="text" id="fseconds" value=""><br>
<input type="button" id="send" value="Enter">
</form>
,我的JS是:
var setHour = document.getElementById("fhours").value;
var setMinute = document.getElementById("fminutes").value;
var setSecond = document.getElementById("fseconds").value;
,而這意味着使用它的功能:如果我把一個數字值
function setTheClockByButton() {
setTheClock(setHour, setMinute, setSecond);
alert(setHour);
}
它的HTML表單工作正常(像這樣)
<span>Hours: </span><input type="text" id="fhours" value="3"><br>
但它不接受來自鍵盤的任何數據。
當然,我有相關的表格的onclick功能:
document.getElementById("send").onclick = setTheClockByButton;
(否則它會做沒有意義)。
你沒asocciated事件,以檢查是否值被改變。 – 2014-11-02 15:57:44
您得到字段值的賦值語句只發生一次。代碼不會在這些變量和字段值之間創建某種永久關係。當字段值因用戶鍵入內容而更改時,變量將不會更新。 – Pointy 2014-11-02 15:58:08
我剛剛編輯帖子,我有onclick功能,我忘了提及它.. – formatc2013 2014-11-02 16:22:15