我有一个问题,我没有找到它在哪里,我向你解释一下,我有一个 page.php,它集成了一个 form.php,在这个 page.php 中,我有一个 page1.php,它也集成了,并且它还有 form.php,在这种形式中,我只有复选框,我的函数 jquery 可以与 pahe.php 一起正常工作,但不能与 page1.php 一起工作,我不明白为什么
页面.php
<div class="left" style="float: left;">
<?php include('C_User_file/Planning/Form/Start/FStartT1.php'); ?>
</div>
page1.php
<div class="left" style="float: left;">
<?php include('C_User_file/Planning/Form/Start/FStartT1.php'); ?>
</div>
FStartT1.php
<label>
<input type="checkbox" id="cbox1" value="1" checked="checked" name="ALL1">
ALL
</label>
<label>
<input type="checkbox" id="cbox2" value="1" name="FMS1">
FMS
</label>
<label>
<input type="checkbox" id="cbox3" value="1" name="CPT1">
CPT
</label>
jquery.js
$("#cbox1" ).click(function(){
$('input[name=ALL1]').attr('checked', true);
$('input[name=FMS1]').attr('checked', false);
$('input[name=CPT1]').attr('checked', false);
});
$("#cbox2" ).click(function(){
$('input[name=ALL1]').attr('checked', false);
$('input[name=FMS1]').attr('checked', true);
$('input[name=CPT1]').attr('checked', false);
});
$("#cbox3" ).click(function(){
$('input[name=ALL1]').attr('checked', false);
$('input[name=FMS1]').attr('checked', false);
$('input[name=CPT1]').attr('checked', true);
});
在 page.php 上工作正常,但在 page1.php 上根本不起作用,感谢您的帮助
小心,我的page1.php包含在page.php中
最佳答案
通过查看你的代码,我了解了一件事。
FStartT1.php
即您的 FORM 已被导入 2 次。
因此从技术上讲,加载页面时您有 2 个表单字段。如果您有疑问,只需在 Chrome 上按 ctr+u
并检查页面源代码即可。您会发现 2 种形式。
这意味着 ID 重复。所以 jQuery 无法处理它。 ID 必须是唯一的。
因此,以下部分将不起作用。
$("#cbox1" ).click(function(){
});
$("#cbox2" ).click(function(){
});
$("#cbox3" ).click(function(){
});
解决方案: 让它成为一个类而不是ID。并像这样调用
<label>
<input type="checkbox" class="cbox1" value="1" checked="checked" name="ALL1">
ALL
</label>
<label>
<input type="checkbox" class="cbox2" value="1" name="FMS1">
FMS
</label>
<label>
<input type="checkbox" class="cbox3" value="1" name="CPT1">
CPT
</label>
在你的 jQuery 中,
$(".cbox1" ).click(function(){
});
$(".cbox2" ).click(function(){
});
$(.cbox3" ).click(function(){
});
关于javascript - PHP 中的 JQuery 已检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44001279/