如何捕获并自定义Contact form 7插件中的每个复选框?
我在一个字段中有一个复选框列表。
我想要做的是使用jQuery为每个复选框添加属性和值。
像这样:NG_TABLE_DIRECTIVES
这是我的HTML代码:
$("input['type=checkbox']:nth-child(3)").attr("data-price", 500).addClass("cf7-checkbox");
非常感谢!!!
答案 0 :(得分:0)
您尝试选中复选框的方式可能不对,这是循环显示所有复选框的方法:
var type = null;
$("input").each(function()
{
type = $(this).attr("type");
if(type == "checkbox")
{
$(this).attr("data-price", 500);
$(this).addClass("cf7-checkbox");
}
});
答案 1 :(得分:0)
此选择器不起作用,因为输入元素不会共享同一个父级。
$("input['type=checkbox']:nth-child(3)").attr("data-price", 500).addClass("cf7-checkbox");
所以我找到了这个解决方案:
$('.wpcf7-checkbox .wpcf7-list-item:nth-child(3) input').attr("data-price", 500).addClass("cf7-checkbox");