<!DOCTYPE html><html><head> ? ?<title> 事件</title> ? ?<script type="text/javascript"> ? ? ? ?function count() { ? ? ? ? ? ?//獲取第一個輸入框的值 ? ? ? ? ? ?var text1 = document.getElementById("text1").value; ? ? ? ? ? ?alert('1'); ? ? ? ? ? ?//獲取第二個輸入框的值 ? ? ? ? ? ?var text2 = document.getElementById("text2").value; ? ? ? ? ? ?//獲取選擇框的值 ? ? ? ? ? ?var sel = document.getElementById("select").value; ? ? ? ? ? ?switch (sel) { ? ? ? ? ? ? ? ?case "+": ? ? ? ? ? ? ? ? ? ?document.getElementById("fruit").value = text1 * 1 + text2 * 1; ? ? ? ? ? ? ? ?case "-": ? ? ? ? ? ? ? ? ? ?document.getElementById("fruit").value = text1 * 1 - text2 * 1; ? ? ? ? ? ? ? ?case "*": ? ? ? ? ? ? ? ? ? ?document.getElementById("fruit").value = text1 * 1 + (text2 * 1); ? ? ? ? ? ? ? ?case "/": ? ? ? ? ? ? ? ? ? ?document.getElementById("fruit").value = text1 * 1 + (text2 * 1); ? ? ? ? ? ?} ? ? ? ?} ? ?</script></head><body><input type='text' id='txt1'/><select id='select'> ? ?<option value='+'>+</option> ? ?<option value="-">-</option> ? ?<option value="*">*</option> ? ?<option value="/">/</option></select><input type='text' id='txt2'/><input type='button' value=' = ' onclick="count()"/> <!--通過 = 按鈕來調用創建的函數,得到結果--><input type='text' id='fruit'/></body></html>
javascript 初級的東西 alert("1");這個都彈不出來
那管你的
2017-05-10 01:16:49