【发布时间】:2021-10-14 21:44:28
【问题描述】:
我已经使用联系表 7 在每个产品页面上创建了一个产品查询表。表格包含每个产品的复选框,以帮助查询。如果用户在相应的产品页面上,如何自动将特定产品复选框设置为 true/on?
我在获取页面标题的表单中添加了一个动态隐藏字段。
联系表格&在每个复选框的名称字段中生成一个复选框数组name="products[]"
理想情况下,我希望脚本循环并选择与隐藏字段匹配的复选框,有人可以告诉我该怎么做吗?
下面是我当前的 jquery
$( document ).ready(function() {
var get_product_name = $('#product-name').val(); // hidden field value
if(get_product_name == 'product-page-title')
{
$('CHECKBOX_HERE').prop('checked', true);
}
});
联系表格 7 生成的 HTML...
<span class="wpcf7-form-control-wrap page-title">
<input type="hidden" name="page-title" value="Product template" size="40" class="wpcf7-form-control wpcf7dtx-dynamictext wpcf7-dynamichidden" aria-invalid="false">
</span>
<span class="wpcf7-form-control-wrap products">
<span class="wpcf7-form-control wpcf7-checkbox">
<span class="wpcf7-list-item first"><label><input type="checkbox" name="products[]" value="Product One"><span class="wpcf7-list-item-label">Product One</span></label>
</span>
<span class="wpcf7-list-item"><label><input type="checkbox" name="products[]" value="Product Two"><span class="wpcf7-list-item-label">Product Two</span></label>
</span>
<span class="wpcf7-list-item"><label><input type="checkbox" name="products[]" value="Product Three"><span class="wpcf7-list-item-label">Product Three</span></label>
</span>
<span class="wpcf7-list-item"><label><input type="checkbox" name="products[]" value="Product Four"><span class="wpcf7-list-item-label">Product Four</span></label>
</span>
<span class="wpcf7-list-item last"><label><input type="checkbox" name="products[]" value="Product Five"><span class="wpcf7-list-item-label">Product Five</span></label>
</span>
</span>
</span>
如你所见,我的技能有限
【问题讨论】:
标签: jquery arrays wordpress checkbox contact-form-7