我想添加+ 10%的值,如果該值被選中,但在我可以實現它之前,我需要使它正常工作,頁面的第一個不應刷新和當我添加一個值,然後我想改變它到另一個我想從另一個文本框的舊值減去...我嘗試了一個簡單的if/else if/else語句,但由於第一個錯誤它不會工作,我甚至不確定它是否正常工作。下面是代碼:錯誤下拉列表(JS)
<!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>
嘗試更改document.form到document.forms [0],你應該通過 – Satya 2013-04-23 12:28:12
nope仍然不能正常工作 – aleksXPO 2013-04-23 12:32:20