这是我的代码。我希望显示警报(“SHOW ME!!”),但它一直工作到那时,所以前面的行导致了问题。我知道如何解决它。这可能是我传递对函数的引用的方式吗?谢谢!!!
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#Sub1").click(function(){
readIngred($("#ingredForm"));
});
});
</script>
<script type="text/javascript">
function readIngred(form) {
var checked;
var checkedBoxes;
//Create an array of checked radio buttons
checked = form.elements["checkSet"];
alert("SHOW ME!!!");
checkedBoxes = new Array(checked.length);
for (var i = 0, j = 0; i < radios.length; i++, j++) {
if (checked[i].checked == true) {
checkedBoxes[j] = checked[i];
} else j--;
}
var c = 0;
while (checkedBoxes[c] !== null) {
c++;
}
alert("You picked " + c + " ingredients");
}
</script>
</head>
<body>
<form id="ingredForm">
<ul style="list-style-type:none;">
<li><input type="checkbox" name="checkSet" value="Pep">Pep</li>
<li><input type="checkbox" name="checkSet" value="Mush">Mush</li>
<li><input type="checkbox" name="checkSet" value="Olive">Olive</li>
<li><input type="checkbox" name="checkSet" value="Cheese">Cheese</li>
</ul>
<input type="submit" name="Submit_Button" id="Sub1" value="Send">
</form>
</body>