我对这个程序的结果有疑问:当我检查“保护器”、“耳机”、“保护套”和“游戏”时,我应该收到“Kindle”、“诺基亚”和“Wii”。但是,我只收到一个值 - “Kindle”(在 Google Chrome 和 Internet Explorer 中)。此外,我收到了 Opera 中的所有值(也是重复的)。你能帮我解决这些问题吗?提前致谢。
<html>
<head>
<script type="text/javascript">
function product(){
var checkboxes = document.getElementsByName('checkboxes');
var i=0;
var j=0;
var tech = [
["Kindle","Protector"],
["Iphone","Headset"],
["Iphone","US Charger"],
["Iphone","USB cable"],
["Iphone","Case"],
["Nokia","Protector"],
["Nokia","Headset"],
["Nokia","Case"],
["Wii","Games"]
];
for (i=0 ; i < tech.length; i++){
for(j=0 ; j< checkboxes.length; j++){
if ((tech[i][1] == checkboxes[j].value)&&(checkboxes[j].checked)){
document.write(tech[i][0]);
document.write("<br>");
}
}
}
}
</script>
</head>
<body>
<form name="Accessories">
<input type="checkbox" name="checkboxes" value="Protector"> Protector <br>
<input type="checkbox" name="checkboxes" value="Headset"> Headset <br>
<input type="checkbox" name="checkboxes" value="US Charger"> US Charger <br>
<input type="checkbox" name="checkboxes" value="USB cable"> USB cable <br>
<input type="checkbox" name="checkboxes" value="Case"> Case <br>
<input type="checkbox" name="checkboxes" value="Games"> Games </br>
<input type="button" name="Check" onClick="product()" value="Search a product">
</form>
</body>
</html>