简体   繁体   English

PHP中的“全选”复选框,其中包含header.php

[英]“select all” check box in PHP with header.php included in it

I have a PHP page with simple script to "Check All" the checkboxes of the page. 我有一个带有简单脚本的PHP页面,可以“全部选中”页面的复选框。

I have to include a header.php in my code, and that is the area of problem. 我必须在代码中包含header.php,这就是问题所在。

When i don't include it, the code works fine. 当我不包括它时,代码工作正常。 But when i include it code does not work, means CHECK ALL button does not selects all checkboxes. 但是,当我将其包含在内时,代码将无法正常工作,这意味着“全部检查”按钮不会选中所有复选框。

My code is -- 我的代码是-

checkall.php

<html>
<body>
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('foo');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<?php include('header.php'); ?>

<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>

<input type="checkbox" name="foo" value="bar1"> Bar 1<br/>
<input type="checkbox" name="foo" value="bar2"> Bar 2<br/>
<input type="checkbox" name="foo" value="bar3"> Bar 3<br/>
<input type="checkbox" name="foo" value="bar4"> Bar 4<br/>
<?php include('footer.php'); ?>
</body>
</html>

I have tried all suggestions By Can Berk Güder in this Question . 我已经尝试过Can Berk Güder此问题中提出的所有建议。

Any Suggestions...??? 有什么建议么...???

i do not know if it help or not but u just can try change the include to include_once 我不知道是否有帮助,但是您可以尝试将include更改为include_once

<html>
<body>
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('foo');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<?php  include_once 'header.php';  ?>

<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>

<input type="checkbox" name="foo" value="bar1"> Bar 1<br/>
<input type="checkbox" name="foo" value="bar2"> Bar 2<br/>
<input type="checkbox" name="foo" value="bar3"> Bar 3<br/>
<input type="checkbox" name="foo" value="bar4"> Bar 4<br/>
<?php  include_once 'footer.php';  ?>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM