如何解决如何单击带有URL的复选框?
我了解我们可以使用URL以HTML表单预先填充一些数据。例如,www.example.com/?itemname=sth
这一次,我想通过URL执行单击操作,以使过滤器正常工作。我已经编写了以下代码来单击该复选框,但是它不起作用,请问我该如何解决?谢谢。
谢谢我尝试过的人,只需选中该复选框即可,但是由于我的过滤器需要单击操作才能触发,所以这就是为什么我想单击一下来实现!
<label class="form-check-label">
<input type="checkbox" class="form-check-input product_check" id="Tutor_subject_1" name="Maths" value="Maths">Maths<br>
<?php if (isset($_GET['itemname']) && $_GET['itemname'] === 'sth' ): ?>
<script>document.getElementsByName("Maths").click();</script>
<?php endif; ?>
</label>
解决方法
显然不需要javascript,只需在PHP中添加checked
属性:
<input
type="checkbox"
class="form-check-input product_check"
id="Tutor_subject_1"
name="Maths"
value="Maths"
<?= (isset($_GET['itemname']) && $_GET['itemname'] === 'sth') ? ' checked' : '' ?>
>Maths<br>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。