[英]“select all” check box in PHP with header.php included in it
我有一个带有简单脚本的PHP页面,可以“全部选中”页面的复选框。
我必须在代码中包含header.php,这就是问题所在。
当我不包括它时,代码工作正常。 但是,当我将其包含在内时,代码将无法正常工作,这意味着“全部检查”按钮不会选中所有复选框。
我的代码是-
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>
我已经尝试过Can Berk Güder
在此问题中提出的所有建议。
有什么建议么...???
我不知道是否有帮助,但是您可以尝试将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.