![](/img/trans.png)
[英]How to validate form based on input type=text/radio/checkbox using jQuery Validation Plugin
[英]How to get a value of input[type=checkbox] using jQuery and pretty checkbox plugin
現在,我在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>
到目前為止,我在JS中有什么:
$('.prettycheckbox').click(function () {
var clickedValue = $(this).//here I need some code to get the input before
alert('Value is ' + clickedValue);
});
因此,我基本上需要獲取被單擊的div.prettycheckbox內部的輸入字段的值(16; value =“ 16”)。
怎么做?
$('.prettycheckbox').click(function () {
var clickedValue = $(this).find(':checkbox').val();
alert('Value is ' + clickedValue);
});
var clickedValue = $(this).children('.car_type:checkbox').val();
試試這個代碼:
$('.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.