html5+JavaScript使用表单实现输入两个数,单击相乘或相加,输出不同结果
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#t1,#t2{
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<form action="form.html" method="get">
<input type="text" id="t1" name="num1"/>
<input type="text" id="t2" name="num2"/><br />
<input type="submit" id="b1" value="+" name='fuhao'/>
<input type="submit" id="b2" value="*" name='fuhao'/>
</form>
</body>
</html>
form.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<script>
window.onload=function(){
var nr = window.location.search.substring(1).split('&');
if(nr[2].split('=')[1]=='%2B'){
document.write(parseInt(nr[0].split('=')[1]) + parseInt(nr[1].split('=')[1]))
return false
}
document.write(parseInt(nr[0].split('=')[1]) * parseInt(nr[1].split('=')[1]))
}
</script>
</html>
评论 (0)