【发布时间】:2016-06-29 12:24:08
【问题描述】:
如何捕捉和自定义 Contact form 7 插件中的每个复选框?
我在单个字段中有一个复选框列表。
我想要做的是使用 jQuery 为每个复选框添加一个属性和值。
像这样:
$("input['type=checkbox']:nth-child(3)").attr("data-price", 500).addClass("cf7-checkbox");
这是我的 html 代码:
<span class="wpcf7-form-control-wrap list-tosafot1">
<span class="wpcf7-form-control wpcf7-checkbox" id="options1st">
<span class="wpcf7-list-item first">
<input type="checkbox" name="list-tosafot1[]" value="price-100" />
<span class="wpcf7-list-item-label">Checkbox1 - price 100</span>
</span>
<span class="wpcf7-list-item">
<input type="checkbox" name="list-tosafot1[]" value="price-200" />
<span class="wpcf7-list-item-label">Checkbox2 - price 200</span>
</span>
<span class="wpcf7-list-item">
<input type="checkbox" name="list-tosafot1[]" value="price-300" />
<span class="wpcf7-list-item-label">Checkbox3 - price 300</span>
</span>
<span class="wpcf7-list-item">
<input type="checkbox" name="list-tosafot1[]" value="price-400" />
<span class="wpcf7-list-item-label">Checkbox4 - price 400</span>
</span>
<span class="wpcf7-list-item last">
<input type="checkbox" name="list-tosafot1[]" value="price-500" />
<span class="wpcf7-list-item-label">Checkbox5 - price 500</span>
</span>
</span>
</span>
非常感谢!!!
【问题讨论】:
-
复选框有id吗?
-
请添加更多信息,您是否遇到任何错误,它无法正常工作。还要添加一段代码,以便我们检查发生了什么。谢谢。
-
我认为您尝试在 jQuery 中选择复选框的方式是错误的。
标签: jquery wordpress checkbox contact-form-7