同樣代碼第一遍跑沒問題,網(wǎng)頁退回復(fù)制粘貼再次提交就不行了,但是粘貼樓上的完美回答就沒事
這樣var應(yīng)該沒錯(cuò)吧?直覺告訴我這是網(wǎng)頁編輯器的問題?
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?
? var a=parseInt(document.getElementById("txt1").value);
? ? ?var b = parseInt(document.getElementById("txt2").value);?
?var d;
var c = document.getElementById("select").value;?
? ?switch (c)
? ? {
? ? ? ? case "+":
? ? ? ? ? var d = a+b;
? ? ? ? ? ?break;
? ? ? ? case "-":
? ? ? ? ? ?d = a-b;
? ? ? ? ? ?break;
? ? ? ? case "*":
? ? ? ? ? d = a*b;
? ? ? ? ? break;
? ? ? ? default:
? ? ? ? ? ?d = a/b;
? ? ? ? ??
? ? }
? ? document.getElementById("fruit").value = d;
? ?}
? </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()"/> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' />? ?
?</body>
</html>
2019-03-22
上面這句 "fruit")的反括號(hào)是中文字符的,需要改成英文的。
測(cè)試了下可以運(yùn)行?(? ??_??)?