我正在使用:http://blogs.digitss.com/javascript/jquery-javascript/jquery-fancy-custom-radio-and-checkbox/
简单代码:
<input type="radio" id="a1" class="b1" name="shipping" checked value="single">
<input type="radio" id="a1" class="b1" name="shipping" value="married">
<input type="radio" id="a1" class="b1" name="shipping" value="widowed">
简单的头部:
$(document).ready(function(){
$(".radio").dgStyle();
$(".checkbox").dgStyle();
});
如果我添加到 $(document).ready ,在 ($".checkbox").dgStyle(); 之后以下内容:
alert($('input:radio[name=shipping]:checked').val());
它工作正常!
但是 - 如果我做那样的事情,它是行不通的:
$(function() {
$("input:radio[name=shipping]:checked").change(function() {
alert("123");
});
});
我尝试删除 :checked,但仍然无法正常工作。
- 也许您知道相同颜色的不同 jquery 自定义按钮,哪个可以做到......?
最佳答案
好的,我明白了:
$(".radio").click(function() {
alert('ID : ' + $(this).find('input:radio').prop('id'));
alert('Value : ' + $(this).find('input:radio').prop('value'));
});
关于javascript - jquery 在变化时获取单选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14092287/