點(diǎn)擊無(wú)反應(yīng),求解哪里有錯(cuò)誤
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? ?var result;
? ? ?var x=document.getElementById("txt1").value;
? ? ?var y=document.getElementById("txt2").value;
? ? ?var z=document.getElementById("select").value;
? ? ?switch(z){
? ? ?case "+":
? ? ? ? ?result=parseInt(x)+parseInt(y);
? ? ? ? ?break;
? ? ?case "-":
? ? ? ? ?result=parseInt(x)-parseInt(y);
? ? ? ? ?break;
? ? ?case "*":
? ? ? ? ?result=parseInt(x)*parseInt(y);
? ? ? ? ?break;
? ? ?default:
? ? ? ? ?result = parseInt(x) / parseInt(y);
? ? }
? ? ?document.getElementById("fruit").value = result;
? ?}
? </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>
2016-08-01
沒(méi)有錯(cuò)誤。。。我運(yùn)行了一下 可以點(diǎn)擊顯示結(jié)果。
2016-08-01
主要有兩個(gè)問(wèn)題,第一個(gè)問(wèn)題是switch-case語(yǔ)句的用法問(wèn)題,case后面要用單引號(hào),即case '+',我記得之前看過(guò)原因,但是現(xiàn)在找不到了-,-;第二個(gè)問(wèn)題是你寫(xiě)的case '*'中break后面的分號(hào)是中文的分號(hào)。應(yīng)該就是這兩個(gè)問(wèn)題了~
2016-08-01
<option value='-'>-</option> 引號(hào)為應(yīng)該是單引號(hào)
2016-08-01
var result = '';