如果复选框名称为'name []',如何选中所有复选框 [英] How to check all the checkboxes if checkbox name is 'name[]'
问题描述
因为有时候我遇到了我想检查的问题或者
取消选中所有复选框。如果我选中复选框
数组的名称为''chkbx_ary''那么我可以选中/取消选中所有复选框
(代码粘贴在下面)。但是如果复选框数组的名称是
''chkbx_ary []''那么它就失败了。我希望这个名字是''chkbx_ary []''
因为我想在服务器端访问这个数组。
虽然可能不需要看到php部分但是我还在粘贴
代码。
< script language =" JavaScript" type =" text / javascript">
函数CheckAll(字段)
{
for(loop = 0; loop< field .length; loop ++)
{
field [loop] .checked = true;
}
}
函数UnCheckAll(字段)
{
for(loop = 0; loop< field.length; loop ++)
{
field [loop] .checked = false;
}
}
< / script>
<?php
echo''< form name =" TestSelect_Form"方法= QUOT; GET" action =" TestList.php"
enctype =" text / plain" style =" margin:0px">
< input type =" radio"名称= QUOT; SelectOrNot" value =" Select_All"
onClick =" CheckAll(document.TestSelect_Form.SelectM odule)"
style =" position:absolute; left:290px; top :140px; z-index:6">
< input type =" radio"名称= QUOT; SelectOrNot" value =" Uncheck_All"
onClick =" UnCheckAll(document.TestSelect_Form.Selec tModule)"检查
style =" position:absolute; left:400px; top:140px; z-index:7">'';
$ file_name =" CONF /testselect.txt" ;;
$ fp_TstSlct = fopen(" $ file_name"," r")或die(发生了一些错误
打开时'' testSelect.txt");
$ TopPos = 170;
while(!feof($ fp_TstSlct))
{
$ TstSlct_data = fgets($ fp_TstSlct);
preg_match_all(" /([#] *)(。*)\ s(\d +)\ * * ;;# ] *(。*)/" ;, $ TstSlct_data,
$ match,PREG_PATTERN_ORDER);
if($ match [2] [0]!= NULL){ //检查模块是否存在
与否。可能只是评论已被提出。对于。例如
################### DSL HOME #########
if($ match [1] [0] == NULL){//检查行是否以
开头
''#''或不是
echo''<输入类型= QUOT;复选框"名称= QUOT; SelectModule []" value =''。
$ match [2] [0]。 ''checked =" checked" style =" position:absolute; left:
90px; top:''。 $ TopPos。 ''px">'';
}其他{
echo''< input type ="复选框"名称= QUOT; SelectModule []" value =''。
$ match [2] [0]。 ''style =" position:absolute; left:90px; top:''。 $ TopPos。
''px">'';
}
echo''< div id =" ;文字3"风格= QUOT;位置:绝对的;溢出:隐藏;
左:130px;最佳:'' 。 $ TopPos。 PX;宽度:79px;身高:16px">< div
class =" wpmd">'';
echo''< div>< font face =" Arial>''。 $ match [2] [0]。 ''< / font>< / div>'';
echo''< / div>< / div>'';
$ TopPos = $ TopPos + 25;
}
}
fclose($ fp_TstSlct);
echo''< input name =" ConfigureTestList"类型= [提交" value =" Next"
style =" position:absolute; left:326px; top:403px; z-index:16">
< / form> ;
< div id =" text1"风格= QUOT;位置:绝对的;溢出:隐藏;左:
265px;顶:118px;宽度:69px; family:宋体; z-index:9">< div
class =" wpmd">
< div>< font class =" ws12" face =" Arial">选择全部< / font>< / div>
< / div>< / div>
< ; div id =" text2"风格= QUOT;位置:绝对的;溢出:隐藏;左:
371px;顶:118px;宽度:85px; family:宋体; z-index:10">< div
class =" wpmd">
< div>< font class =" ws12" face =" Arial">取消选中所有< / font>< / div>
< / div>< / div>'';
?> ;
请有人建议解决方案因为我完全卡住了。
提前多多感谢。
Hi, since sometime I''m stuck in a problem where I want to check or
uncheck all the checkboxes. If I''m choosing name for the checkbox
array as ''chkbx_ary'' then I''m able to check/uncheck all the checkboxes
(code pasted below). But if name of the checkbox array is
''chkbx_ary[]'' then it''s failing. I want the name to be ''chkbx_ary[]''
because I want to access this array at server side.
Though one may not require to see php part but I''m still pasting the
code.
<script language="JavaScript" type="text/javascript">
function CheckAll(field)
{
for (loop=0; loop < field.length; loop++)
{
field[loop].checked = true;
}
}
function UnCheckAll(field)
{
for (loop=0; loop < field.length; loop++)
{
field[loop].checked = false;
}
}
</script>
<?php
echo ''<form name="TestSelect_Form" method="GET" action="TestList.php"
enctype="text/plain" style="margin:0px">
<input type="radio" name="SelectOrNot" value="Select_All"
onClick="CheckAll(document.TestSelect_Form.SelectM odule)"
style="position:absolute;left:290px;top:140px;z-index:6">
<input type="radio" name="SelectOrNot" value="Uncheck_All"
onClick="UnCheckAll(document.TestSelect_Form.Selec tModule)" checked
style="position:absolute;left:400px;top:140px;z-index:7">'';
$file_name = "CONF/testselect.txt";
$fp_TstSlct = fopen("$file_name", "r") or die("Some error occurred
while opening ''testSelect.txt");
$TopPos = 170;
while(!feof($fp_TstSlct))
{
$TstSlct_data = fgets($fp_TstSlct);
preg_match_all("/([#]*)(.*)\s(\d+)\s*[;#]*(.*)/", $TstSlct_data,
$match, PREG_PATTERN_ORDER);
if ( $match[2][0] != NULL ) { //Checking whether module is present
or not. May be only comments have been put. For. e.g.
###################DSL HOME#########
if ( $match[1][0] == NULL ) { //Checking if line is starting with
''#'' or not
echo ''<input type="checkbox" name="SelectModule[]" value='' .
$match[2][0] . '' checked="checked" style="position:absolute;left:
90px;top:'' . $TopPos . ''px">'';
} else {
echo ''<input type="checkbox" name="SelectModule[]" value='' .
$match[2][0] . '' style="position:absolute;left:90px;top:'' . $TopPos .
''px">'';
}
echo ''<div id="text3" style="position:absolute; overflow:hidden;
left:130px; top:'' . $TopPos . ''px; width:79px; height:16px"><div
class="wpmd">'';
echo ''<div><font face="Arial">'' . $match[2][0] . ''</font></div>'';
echo ''</div></div>'';
$TopPos = $TopPos + 25;
}
}
fclose($fp_TstSlct);
echo ''<input name="ConfigureTestList" type="submit" value="Next"
style="position:absolute;left:326px;top:403px;z-index:16">
</form>
<div id="text1" style="position:absolute; overflow:hidden; left:
265px; top:118px; width:69px; height:18px; z-index:9"><div
class="wpmd">
<div><font class="ws12" face="Arial">Select All</font></div>
</div></div>
<div id="text2" style="position:absolute; overflow:hidden; left:
371px; top:118px; width:85px; height:18px; z-index:10"><div
class="wpmd">
<div><font class="ws12" face="Arial">Uncheck All</font></div>
</div></div>'';
?>
Please someone suggest the solution as I''m totally stuck.
Thanks a lot in advance.
推荐答案
file_name =" CONF / testselect.txt";
file_name = "CONF/testselect.txt";
fp_TstSlct = fopen("
fp_TstSlct = fopen("
/ >
file_name"," r")或die(在打开''testSelect.txt时发生了一些错误
);
file_name", "r") or die("Some error occurred
while opening ''testSelect.txt");
这篇关于如果复选框名称为'name []',如何选中所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!