gpt4 book ai didi

jquery - 获取复选框的 id? - jQuery

转载 作者:行者123 更新时间:2023-12-03 21:57:27 26 4
gpt4 key购买 nike

嘿,我想知道如何在选中复选框时获取其 id。

这就是我的 HTML 最初的样子:

<div class="check_filter">

<div id="filter">
<input type="checkbox" id="check1" /><label for="check1">Marketing</label>
<input type="checkbox" id="check2" /><label for="check2">Automotive</label>
<input type="checkbox" id="check3" /><label for="check3">Sports</label>
</div>

</div><!-- End check_filter -->

我假设 jQuery 看起来像这样:

$(document).ready(function() {    
$(":checkbox").click(function(){
var id = $(this).attr('id');

$.post("index.php", { id: id });
//return false to ensure the page doesn't refresh
return false;
});
});

我正在尝试获取选中的项目 id,然后将该 id 发布到 mysql 查询中,以从数据库中获取该 id 的结果。

感谢您对此提供的任何帮助。

最佳答案

您可能想要 change事件在这里,像这样:

$(function() {
$(":checkbox").change(function(){
$.post("index.php", { id: this.id, checked: this.checked });
});
});

只要复选框发生更改,就会发布此消息,并让 PHP 端知道 ID 以及是否已选中。

关于jquery - 获取复选框的 id? - jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3363957/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com