點擊等號沒有反應(yīng),找了好幾遍,重新寫了兩遍,還是找不到錯誤,
?<script type="text/javascript">
? ?function count(){
? ? ? ?
? ? //獲取第一個輸入框的值
? ? var txt1=document.getElementById("txt1").value;
//獲取第二個輸入框的值
var txt2=document.getElementById("txt2").value;
//獲取選擇框的值
var infos=document.getElementById("select").value;
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
var txt3;
switch(infos):
{
? ?case"+":txt3=parseInt(txt1)+parseInt(txt2);
? ?break;
? ?case"-":txt3=parseInt(txt1)-parseInt(txt2);
? ?break;
? ?case"*":txt3=parseInt(txt1)-parseInt(txt2);
? ?break;
? ?case"/":txt3=parseInt(txt1)-parseInt(txt2);
? ?break;
? ?default:document.write("無此功能");
}
? ? //設(shè)置結(jié)果輸入框的值?
? ? document.getElementById("fruit").value=txt3;
? ?}
? </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' /> ??
2019-08-20
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?
? ? //獲取第一個輸入框的值
? ? ?var num1 =? document.getElementById("txt1").value;
//獲取第二個輸入框的值
var num2 =? ?document.getElementById("txt2").value;
//獲取選擇框的值
? ? var select = document.getElementById("select").value;
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
switch(select){
? ? case "+":
? ? ? num3 =? parseInt(num1)+parseInt(num2);
? ? break;
? ? case "-":
? ? ? ? ?num3 =? parseInt(num1)-parseInt(num2);
? ? break;
? ? case "*":
? ? ? ? ?num3 =? parseInt(num1)*parseInt(num2);
? ? break;
? ? case "/":
? ? ? ? num3 =? parseInt(num1)/parseInt(num2);
? ? break;
}
? ? //設(shè)置結(jié)果輸入框的值?
? ? document.getElementById("fruit").value = num3;
? ??
? ?}
? </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-08-19
?<input type='button' value=' = ' ?onclick="count()"/>?
解決辦法:這一行你把/>前打個空格,如
?<input type='button' value=' = ' ?onclick="count()" />?
原因:應(yīng)該是編譯器的問題,碰到好多次了
2019-08-18