為什么我的運行后沒有結(jié)果?明明已經(jīng)寫規(guī)范了
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>??
? <script type="text/javascript">
? ?function count(){
? ? ? ?var j="";
? ? ? ?var x=document.getElementById("txt1").value;
? ? ? ?var y=document.getElementById("txt2").value;
? ? ? ?var z=document.getElementById("select").value;
? ? ? ?switch(z){
? ? ? ? ? ?case "-":
? ? ? ? ? ?j=parselnt("x")+parselnt("y")
? ? ? ? ? ?break;
? ? ? ? ? ? case "+":
? ? ? ? ? ?j=parselnt(x)-parselnt(y)
? ? ? ? ? ?break;
? ? ? ? ? ? case "*":
? ? ? ? ? ?j=parselnt(x)*parselnt(y)
? ? ? ? ? ?break;
? ? ? ? ? ? case "/":
? ? ? ? ? ?j=parselnt(x)/parselnt(y)
? ? ? ? ? ?break;
? ? ? ?}
? ? ? ?document.getElementBy("fruit").value=j
? ?}
? </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()" /> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' />? ?
?</body>
</html>
2018-09-11
parseInt? 你寫錯了? l是大寫
2018-09-13
parsenInt(x)不用加引號,+法加這個函數(shù)就行,其他的不用加也行
2018-09-11
正確值(用+ 號? 需要用parseInt(),使用parseInt()函數(shù)可解析一個字符串,并返回一個整數(shù)。)
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title>?
? <script type="text/javascript">
?? function count(){
?????? var j="";
?????? var x=document.getElementById("txt1").value;
?????? var y=document.getElementById("txt2").value;
?????? var z=document.getElementById("select").value;
?????? switch(z){
?????????? case "-":
?????????? j=x-y
?????????? break;
??????????? case "+":
?????????? j=parseInt(x)+parseInt(y)
?????????? break;
??????????? case "*":
?????????? j=x*y
?????????? break;
??????????? case "/":
?????????? j=x/y
?????? }
?????? document.getElementById("fruit").value=j
?? }
? </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()" /> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->
?? <input type='text' id='fruit' />??
?</body>
</html>