gpt4 book ai didi

php - 无法使用 jQuery 获取复选框的值

转载 作者:行者123 更新时间:2023-11-28 12:34:26 28 4
gpt4 key购买 nike

我正在尝试使用 JavaScript 获取所有选定的复选框值,但直到现在我还无法完成它。这是我尝试过的。我做错了什么?

JS:

var femaleMatches = [];
$(".selectFemaleService:checked").each(function() {
console.log('found a female');
femaleMatches.push(this.value);
});

PHP:

echo "<div class='checkbox'><label><input id='selectFemaleServices' name='selectFemaleServices' type='checkbox' value='$id'>$description</label></div>";

最佳答案

您的 jQuery 是按 class 选择的,但您的复选框有一个 id。如果有多个复选框,您应该将 id 更改为 class,这样就不会出现重复项。

echo "<div class='checkbox'>" 
. "<label>"
. "<input class='selectFemaleServices' name='selectFemaleServices' type='checkbox' value='$id'>$description"
. "</label>"
. "</div>";

关于php - 无法使用 jQuery 获取复选框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18659015/

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