[英]How to get a value of input[type=checkbox] using jQuery and pretty checkbox plugin
Right now I have this code on the HTML part: 现在,我在HTML部分上有以下代码:
<div class="clearfix prettycheckbox labelright blue">
<input class="car_type" type="checkbox" value="16" name="" style="display: none;">
<a class="" href="#"></a>
<label for="undefined"></label>
</div>
And What I have so far in JS: 到目前为止,我在JS中有什么:
$('.prettycheckbox').click(function () {
var clickedValue = $(this).//here I need some code to get the input before
alert('Value is ' + clickedValue);
});
So, I basically need to get the value (16; value="16") of the input field inside of div.prettycheckbox that was clicked. 因此,我基本上需要获取被单击的div.prettycheckbox内部的输入字段的值(16; value =“ 16”)。
How to do that? 怎么做?
$('.prettycheckbox').click(function () {
var clickedValue = $(this).find(':checkbox').val();
alert('Value is ' + clickedValue);
});
var clickedValue = $(this).children('.car_type:checkbox').val();
Try this code : 试试这个代码:
$('.prettycheckbox').click(function () {
var clickedValue = $(this).children('input[type=checkbox]').val()
alert('Value is ' + clickedValue);
});
$(this).find('input[type=checkbox]:checked').val();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.