您的当前位置:首页正文

js获取checkbox复选框选中的选项实例

2022-05-29 来源:易榕旅网
js获取checkbox复选框选中的选项实例

有关javascript 获取checkbox复选框的实例数不胜数。js实现:

var form = document.getElementById(\"form2\");

var field = form.elements[\"test2\"];

var option = Dining.getSelectedOption(form, field);var message = \"\";

for (var i = 0, len = option.length; i < len; i++) {

message += \"Select id:\" + option[i].id + \"\\nSelected name:\" + option[i].name + \"\\nSelected value:\" + option[i].value + \"\\n\\n\";}

alert(message);/*获取选中的选项*/

getSelectedOption: function (selectform, selectionfield) {var result = [];var option = null;

for (var i = 0; i < selectionfield.length; i++) {option = selectionfield[i];if (option.checked) {result.push(option);} www.jb51.net}

return result;}


\

因篇幅问题不能全部显示,请点此查看更多更全内容