我正在編寫一個簡單的計算器,其中包含JS & HTML。我正在使用onclick事件輸入類型按鈕。一切都很好,但這種形式只處理數據,如果我點擊按鈕,但如果我從鍵盤按ENTER鍵不起作用。如何使用輸入按鈕和Javascript中的onclick HTML表單
這裏是我的HTML代碼
<form> <input type="text" id="number1"/>
<select id="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="number2"/>
<input type="button" onclick="getData('data.php','divTarget')" value="Calculate"/>
</form>
注:我可以在此頁面上的多個表單,所以我不能使用event.keyCode == 13
的onkeydown事件。因爲它可能會處理任何形式,如果我按ENTER鍵。而且沒有Jquery需要。
對不起,它不工作。這裏是示例鏈接 http://www.hlinker.com/ajax/ –
更新您的代碼在頁面中,我看不到任何區別於您的原始代碼。 – aksu
已更新您的代碼,請重新檢查鏈接 –