請問我這兒哪里出錯了,無法運行出來
<!DOCTYPE? HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數</title>
<script type="text/javascript">
function asd()
{
?var x,y;
?x=parseInt(prompt("輸入第一個數:"));
?y=parseInt(prompt("輸入第二個數:"));
?if(x>y){
??? document.write(x+"大");
}
?else if(x=y){
???? document.write("相等");
?}
?else{
???? document.write(y+"大");
?}
</script>
</head>
<body>
??? <input type="botton" value="點我" onclick="asd()">
</body>
</html>
2017-08-26
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數</title>
<script type="text/javascript">
function asd()
{
var x,y;
x=parseInt(prompt("輸入第一個數:"));
y=parseInt(prompt("輸入第二個數:"));
if(x>y)
{
? ? document.write(x+"大");
}
else if(x==y)
{
? ? document.write("相等");
}
else
{
? ? document.write(y+"大");
}
}
</script>
</head>
<body>
? ? <input type="button" value="點我" onclick="asd()">
</body>
</html>
看看你是哪里錯的?
首先:input的type應該是"button",而不是你的"botton";其次你的asd()函數外面少了一個"{";最后你的if else分支的中間一個(x=y),"="只是賦值符號,如果要判斷兩個數是否相等,應該用"==",兩個等號。
2017-08-27
兩個錯誤 ? ?1.在</script>上面再加一個右括號,2.else if(x=y)改成else if(x==y)
2017-08-26
少了一個右括號
2017-08-26
你js代碼中少了一個括號,同時盡量用寫按鈕的時候沒必要用input標簽