87,990
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>计算器</title>
<script language="javascript">
window.onload = function math(){
x = document.form1.input1;
n = document.form1.input2;
z = document.getElementById("button1");
i = document.form1.select1.selectedIndex;
k = document.form1.select1.options[i].value;
z.onclick=function(){
result = parseFloat(x.value)/*把k放在这里??*/parseFloat(n.value);
alert(result);
}
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="input1" size="5"/>
<select name="select1">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type="text" name="input2" size="5" />
<input type="button" id="button1" value="显示结果" />
</form>
</body>
</html>
//其他不用改,js改成这样就可以了
window.onload = function math(){
x = document.form1.input1;
n = document.form1.input2;
z = document.getElementById("button1");
z.onclick=function(){
k=document.form1.select1.options[document.form1.select1.selectedIndex].text;
alert(eval(parseFloat(x.value)+k+parseFloat(n.value)));
}
}