怎么優(yōu)化這串代碼
<!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); ???????switch(document.getElementById("select").value){ ???????????case?("+"):?document.write(a+b);break; ???????????case?("-"):?document.write(a-b);break; ???????????case?("*"):?document.write(a*b);break; ???????????case?("/"):?document.write(a/b);break; ???????} ???} ??</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='?=?'/>? ???<input?type='text'?id='fruit'?onfocus="count()"/>??? ?</body> </html>
怎么能夠使得點(diǎn)擊等于后,結(jié)果顯示在第三個(gè)文本框
2017-05-09
switch那一段改成如下試試: