当我命名我的控件以便在POST或GET中获取数组时,我经常使用这种表示法。
i often use this notation when i name my controls in order to get an array in POST or GET.
<input name="color[1]" type="text" /> <input name="color[2]" type="text" /> <input name="color[3]" type="text" />所以在我的脚本中我可以做到
so in my scripts i can do
<?php $data=$_GET["color"]; for each ($color as $key=>$value) { doSomething(); } ?>经常发生我需要在javascript中获取这些ID,但我无法得到它们,所以我经常为html中的每个元素添加一个ID,如
Often happens that i need to get those id back in javascript , but i cannot get them , so i often add an ID to each element in html like that
<input name="color[3]" id="color_3" type="text" />因此我可以使用document.getElementsById('color_3')
so that i can use document.getElementsById('color_3')
相反,我想找到使用document.getElementsByName(color [3])... 的方法,但我无法让它真正起作用。
Instead i would like to find way to use document.getElementsByName(color[3])... but i cannot really get it to work.
任何帮助?
推荐答案<input name="color[3]" id="color_3" type="text" /> var element = document.getElementsByName("color[3]"); alert(element[0].id);
它运作正常..你应该想到的是返回类型是一个元素数组不是单个元素
It works fine .. The thing you should have in your mind is Return type is an array of elements not a single element
更多推荐
GetElementsByName包含名称之类的数组
发布评论