问答详情
源自:6-11 编程练习

错在哪里,ReferenceError: count is not defined,一直找不到

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>函数的编程练习</title>

</head>

<script type="text/javascript">

window.onload=function () {

var oText1=document.getElementById('text1').value;

var oText2=document.getElementById('text2').value;

var oLie=document.getElementById('lie').value;

var oFriut=document.getElementById('friut').value;

var result="";

function count() {

switch (oLie) {

case "+":

result=oText1+oText2;

break;

case "-":

result=oText1-oText2;

break;

case "*":

result=oText1*oText2;

break;

default:

result=oText1/oText2;

break;

}

oFriut=result;

}

};

</script>

<body>

<input type="text" name="text1" id="text1">

<input type="text" name="text2" id="text2">

<select id="lie">

<option id="+">+</option>

<option id="-">-</option>

<option id="*">*</option>

<option id="/">/</option>

</select>

<input type="button" name="btn" id="btn" onclick="count()">

<input type="text" name="friut" id="friut">

</body>

</html>



提问者:Mileswongke 2016-10-16 16:39

个回答

  • 慕少4929721
    2016-10-16 17:43:30

    加载函数错了,不需要window.onload,只要那个点击事件的函数count()就行了