請(qǐng)問(wèn)為什么運(yùn)行結(jié)果出不來(lái)呢
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? var x,y,result,o;
? ? x=document.getElementById('txt1').value;??
? ? //獲取第一個(gè)輸入框的值
? ? y=document.getElementById('txt2').value;
//獲取第二個(gè)輸入框的值
o=document.getElementById('select').value;
//獲取選擇框的值
? ? switch(o){
? ? ? ? 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')=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>
2019-03-06
獲取fruit后,你的值呢,value少寫了? ?發(fā)現(xiàn)了嗎