javascript 编写的小程序提示"缺少对象",高手帮解决下

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:41:25
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>幸运52</title>
<script>
var Commodity="诺基亚6670";
var flag=0;
var price_phone=2000;
var price_guess;
function begin()
{
flag=1;
document.forms[0].elements[1].value=Commodity;
}
function showInfo()
{
if(flag)
{
if(price_guess>price_phone)
{
alert("高了高了!");
document.forms[0].elements[2].value="";
price_guess="";
}
if(price_guess<price_phone)
{
alert("低了低了!");
document.forms[0].elements[2].value="";
price_guess="";
}
if(price_guess=price_phone)
{
alert("恭喜恭喜!");
newGame();
}
}
}
function newGame()

很简单的问题,你在判断价格后并没有return,这样后面的判断依然会运行
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>幸运52</title>
<script>
var Commodity="诺基亚6670";
var flag=0;
var price_phone=2000;
var price_guess;
function begin()
{
flag=1;
document.forms[0].elements[1].value=Commodity;
}
function showInfo()
{
if(flag)
{
if(price_guess>price_phone)
{
alert("高了高了!");
document.forms[0].elements[2].value="";
price_guess="";
return;
}
if(price_guess<price_phone)
{
alert("低了低了!");
document.forms[0].elements[2].value="";
price_guess="";
return;
}
if(price_guess=price_phone)
{
alert("恭喜恭喜!");
newGame();
}
}
}