[英]Contact form 7 checkbox Check
My contact form 7 checkbox elements are like this,我的联系表单 7 复选框元素是这样的,
[checkbox vitesturu id:checkbox3 use_label_element exclusive "Engelli"]
[checkbox vitesturu id:checkbox2 use_label_element exclusive "Manuel Vites (Düz)"]
I want to print value to input value when checkbox is clicked.我想在单击复选框时将值打印到输入值。
<input type="text" id="textbox2" />
The js code I use is like this.我用的js代码是这样的。
$(document).ready(function() {
// Returns male in textbox2 if checkbox2 checked.
$('#checkbox2').click(function() {
if ($('#checkbox2').is(":checked") == true) {
$('#textbox2').val('Male');
} else {
$('#textbox2').val('');
}
});
// Returns female in textbox2
// if checkbox2 checked.
$('#checkbox3').change(function() {
if ($('#checkbox3').is(":checked") == true) {
$('#textbox2').val('Female');
} else {
$('#textbox2').val('');
}
});
});
However, this is not working.但是,这是行不通的。 I guess I can't select the checkbox component.
我想我无法选择复选框组件。 What is the problem?
问题是什么?
you need to check the :checked
on the checkbox input directly, but Contact Form 7 adds the id to the wrapping element.您需要直接检查复选框输入上的
:checked
,但是 Contact Form 7 将 id 添加到包装元素中。
The solution is this:解决办法是这样的:
$(document).ready(function() {
// Returns male in textbox2 if checkbox2 checked.
$('#checkbox2').change(function() {
// CHANGED THIS SELECTOR
if ($('#checkbox2 input').is(':checked')) {
$('#textbox2').attr('value', 'Male');
} else {
$('#textbox2').attr('value', '');
}
});
// Returns female in textbox2
// if checkbox2 checked.
$('#checkbox3').change(function() {
// CHANGED THIS SELECTOR
if ($('#checkbox3 input').is(':checked')) {
$('#textbox2').attr('value', 'Female');
} else {
$('#textbox2').attr('value', '');
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.