English 中文(简体)
以超文本方式选择所有检查箱
原标题:Select all Checkboxes in HTML

iii

我有一张超文本,有几张带有检查箱的物品清单(表格中)。 表中每一行各有以下 co:

<input type= checkbox  name= Events[]  value= 1 >
<input type= checkbox  name= Events[]  value= 2 >
etc

我想用一个“显示所有”的链接名称,在点击时将选择所有项目。

我正在使用以下联合材料,但它没有发挥作用。

    function SelectAll(form)
    {
        for(var i in form.Events.childNodes)
            if(form.Events.childNodes[i].type == "checkbox")
                form.Events.childNodes[i].checked = true;
    }
问题回答

。 活动 would

由于方括号并不适宜于Javad 字典(>o.p) 财产存取简便,你必须使用直线标语,才能做到:

var inputs= form.elements[ Events[] ];

<代码>form.elements Collection (and the form Collection se-form[ Activities[] ] - which is a non-standardised shortcut to same what but with more opportunity of name conflict) is a bit ageschool and has some disabilities like re a one content rather than a list when there s only one content. 或许可以更好地利用<条码>。

var inputs= form.getElementsByName( Events[] );

跟踪:

for (var i= inputs.length; i-->0;)
    inputs.checked= true;

永远不会使用<条码>,用于......,以生成一种射线或类似阵列的序列。 根本不做你们所认为的事情。 旧学校指数化 lo。

这里,你应当努力这样做。

<input class="Events" type= checkbox  name= Events[]  value= 1 >
<input class="Events" type= checkbox  name= Events[]  value= 2 >


function SelectAll(form) {
  for (var i = 0; i < form.elements.length; i ++) {
     if (form.elements[i].type == "checkbox" && form.elements[i].className="Events") {
        form.elements[i].checked = true;
     }
  }
)

这只能用于在<代码><form>标签上直接<>/em>的检查箱,而不是在其他标签内封。

这样做的最简单方式是:

$( :checkbox , form).attr( checked , true);




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签