如果选择了该值,我想为该值添加 +10%,但在我可以实现它之前,我需要使其正常工作,页面的第一个不应该刷新,当我添加一个值然后我想改变它到另一个我希望从另一个文本框中减去旧值......我尝试了一个简单的 if/else if / else 语句,但由于第一个错误它不起作用,我什至不确定它是工作正常。这是代码:
<!doctype html>
<html>
<head>
<title>lol</title>
<meta charset="utf-8">
</head>
<body>
<form action="">
<input type="text" id="hp">
<input type="text" id="ea">
<input type="text" id="ed">
<input type="text" id="pa">
<input type="text" id="pd">
<input type="text" id="sp">
<select>
<option value="hp">HP</option>
<option value="ea">EA</option>
<option value="ed">ED</option>
<option value="pa">PA</option>
<option value="pd">PD</option>
<option value="sp">SP</option>
</select>
<input type="submit" id="sub" onClick = "return at()">
</form>
<script type="text/javascript">
function at () {
var a = document.form.select.options,
i = document.form.select.selectedIndex,
ea = Number(document.form.ea.value),
ed = Number(document.form.ed.value),
hp = Number(document.form.hp.value),
pd = Number(document.form.pd.value),
pa = Number(document.form.pa.value),
sp = Number(document.form.sp.value),
eaS,edS,pdS,paS,spS,hpS = 0;
if(a[i].text === "hp"){
hpS = hp*0.1;
}else if(a[i].text === "ea"){
eaS = ea*0.1
}else if(a[i].text === "ed"){
edS = ed*0.1
}else if(a[i].text === "pa"){
paS = pa*0.1
}else if(a[i].text === "pd"){
pdS = pd*0.1
}else if(a[i].text === "sa"){
spS = sp*0.1
}
document.form.ea.value = eaS;
document.form.ed.value = edS;
document.form.hp.value = hpS;
document.form.pd.value = pdS;
document.form.pa.value = paS;
document.form.sp.value = spS;
return false;
}
</script>
</body>
</html>