写一个页面根据选择框计算工资的计算小程序。
传入参数:var a = document.getElementById('你的标签id').value;
传出参数:var z = document.getElementById('你的标签id');
输出结果:var c = document.getElementById('接收标签id');
c.innerHTML
关联选择框:var sr = document.getElementById('select的id');
var op = sr.selectedIndex;
例子如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript基本语法</title>
</head>
<body>
<select id="city">
<option value="">请选择你所在的城市</option>
<option value="1">上海</option>
<option value="2">深圳</option>
<option value="3">其他</option>
</select><br />
请输入你的工资:
<input type="text" id='input' /><br />
你所得工资是:<p id='p'></p>
<button id='jisuan' onclick="handle()">计算</button>
<script>
function handle(){
var sr = document.getElementById('city');
var op = sr.selectedIndex;
var a = document.getElementById('input').value;
var z = document.getElementById('p');
if (op == 1 && a > 4000){
z.innerHTML = a - (a-4000)*0.1;
}
else if(op == 2 && a > 3500){
z.innerHTML = a - (a-3500)*0.1;
}
else if(op == 3 && a > 3000){
z.innerHTML = a - (a-3000)*0.05;
}
else{
z.innerHTML = a;
}
}
</script>
</body>
</html>
页面效果