判断数字大小的网页

来源:百度知道 编辑:UC知道 时间:2024/06/25 01:55:47
编写客户端脚本,在页面上设置两个文本框,输入 和y。设置一个按钮,点击按钮后,显示提示框,表示两个输入数据的大小关系,x>y, x=y,或x<y

最后要做成网页。
<html>
<head>
<script language="javascript">
function compare(){
if(parseInt(document.form1.a.value) < parseInt(document.form1.b.value)){
alert("x<y");
}if(parseInt(document.form1.a.value) > parseInt(document.form1.b.value)){
alert("x>y");
} else{
alert("x=y");
}

}
</script>
</head>
<form name=form1>
<input name=a type=text/>
<input name=b type=text/>
</form>
<input name="button" type=button onClick="compare()" value="开始"/>
</html>

我自己编了个网页,但出现了问题。只能满足x>y和X=Y,当X<Y时则会另外弹出x=y,求高人指点。

你把else{
alert("x=y");
}
改为
if(parseInt(document.form1.a.value) =parseIn(document.form1.b.value)){
alert("x=y")
}

因为你最后的那个else是只和上个if对应的 要么全用elseif 所以你只要不满足第二个条件的都显示else里面的x=y