Javascript复选框的问题
Issues With Javascript Checkboxes
嗨,我在获取复选框值时遇到了一些问题。对于一个学校项目,我有一份披萨订单表,我想打印一份订单摘要。我在打印浇头时遇到问题。
<label><input type = "checkbox" name = "topping" id = "sausage" value = "Sausage"/> Sausage</label>
<label><input type = "checkbox" name = "topping" id = "pepperoni" value = "Pepperoni"/> Pepperoni</label>
<label><input type = "checkbox" name = "topping" id = "beef" value = "Beef"/> Beef</label>
<label><input type = "checkbox" name = "topping" id = "bacon" value = "Bacon"/> Bacon</label><br />
<label><input type = "checkbox" name = "topping" id = "chicken" value = "Chicken"/> Chicken</label>
<label><input type = "checkbox" name = "topping" id = "ham" value = "Ham"/> Ham</label>
<label><input type = "checkbox" name = "topping" id = "olives" value = "Olives"/> Olives</label>
<label><input type = "checkbox" name = "topping" id = "peppers" value = "Peppers"/> Peppers</label><br />
<label><input type = "checkbox" name = "topping" id = "tomatoes" value = "Tomatoes"/> Tomatoes</label>
<label><input type = "checkbox" name = "topping" id = "mushrooms" value = "Mushrooms"/> Mushrooms</label>
<label><input type = "checkbox" name = "topping" id = "pineapple" value = "Pineapple"/> Pineapple</label>
这是html部分,我有我认为问题所在的javascript函数。
function toppings(inputCollection) {
var toppings = "";
for (var i = 0; i < inputCollection.length; i++) {
if (inputCollection[i].checked) {
toppings = toppings + inputCollection[i].value + " ";
}
}
return toppings;
}
我是javascript的新手,所以如果我犯了一个愚蠢的错误,请不要激怒我。非常感谢
如何调用函数?
这应该做到——topings(document.getElementsByName("toping"))
看看这个例子,它还展示了如何正确使用标签:http://jsbin.com/upeqam
相关文章:
- 复选框与文本内联-JS问题
- 选中复选框的Jquery/Javascript问题使用输入框操作将行从一个表添加到另一个表
- ASP MVC复选框表单提交问题
- 格式问题:下拉复选框
- AngularJS复选框通过$event.target更改问题
- 使用 php 和 javascript Ajax 发送复选框值时遇到问题
- 复选框问题
- jQuery复选框未选中检测问题
- 我正试图获得一个带有复选框的多选下拉列表,在填充项目和获得所有选中的工作时遇到了一些问题
- 使用Knockout和复选框进行ajax调用的问题
- 使用动态父和子复选框时出现问题
- webkit浏览器中的复选框问题
- 复选框说明使用javascript的检索问题
- 为每个选中的复选框显示相同的问题集.(PHP和JS/Jquery)
- Jstree-Can't在AJAX调用中选中复选框,适用于经典调用.一个问题
- AJAX 调用 PHP 复选框问题
- 取消选择所有复选框时出现问题 Un 选中子项之一
- Javascript 价格计算器问题(复选框)
- IE9 问题:动态创建(通过 innerHTML)选项按钮和复选框不起作用
- 这里出了什么问题?复选框不起作用