這代碼有毒,就是不出結(jié)果是什么情況
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var txts1 = parseInt(document.getElementById("txt1").value);
? ? var txts2 =parseInt(document.getElementById("txt2").value);
? ? var options =document.getElementById("select").value;
? ? switch(options){
? ?
? ? case "+":
? ? var nim = parseInt(txts1) + parseInt(txts2);
? ? break;
? ? case "-";
? ? var nim= parseInt(txts1)-parseInt(txts2);
? ? break;
? ? var nim=parseInt(txts1)* parseInt(txts2);
? ? break;
? ? var nim=parseInt(txts1)/parseInt(txts2);
? ? break;
? ? default;
? ?
? ? }
? ? document.getElementById("fruit").value=nim;
? ?}
? ? ? ?
? ?
? ?
? </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()"/> <!--通過(guò) = 按鈕來(lái)調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
2018-10-09
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var txts1 = parseInt(document.getElementById("txt1").value);
? ? var txts2 =parseInt(document.getElementById("txt2").value);
? ? var options =document.getElementById("select").value;
? ? switch(options){
? ?
? ? case "+":
? ? var nim = txts1 + txts2;
? ? break;
? ?
? ? case "-":
? ? var nim = txts1 - txts2;
? ? break;
? ?
? ? case "*":
? ? var nim = txts1 * txts2;
? ? break;
? ?
? ? case "/":
? ? var nim = txts1 / txts2;
? ? break;
? ?
? ?
? ? }
? ? document.getElementById("fruit").value=nim;
? ?}
?</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>
2018-10-09
樓上說(shuō)得對(duì)
2018-10-09
switch/case那里寫(xiě)的有問(wèn)題
switch(options){
? ?
? ? case "+":
? ? var nim = parseInt(txts1)+parseInt(txts2);
? ? break;
? ? case "-":
? ? var nim= parseInt(txts1)-parseInt(txts2);
? ? break;
? ? case "*":
? ? var nim=parseInt(txts1)* parseInt(txts2);
? ? break; ?
? ? default:
? ? var nim=parseInt(txts1)/parseInt(txts2);
? ? break;
? ? }
? ? document.getElementById("fruit").value=nim;
? ?}
? ? ? ?
2018-10-09
我今晚一定給你修整好!