admin管理员组文章数量:1288075
i am using: /
simple code:
<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">
simple head:
$(document).ready(function(){
$(".radio").dgStyle();
$(".checkbox").dgStyle();
});
if i add to $(document).ready , after ($".checkbox").dgStyle(); The following:
alert($('input:radio[name=shipping]:checked').val());
it works fine!
but - if i do something like that, it is not working:
$(function() {
$("input:radio[name=shipping]:checked").change(function() {
alert("123");
});
});
i tried to remove :checked, still not working.
- maybe you know different jquery custom buttons in that same colors, which can does it..?
i am using: http://blogs.digitss./javascript/jquery-javascript/jquery-fancy-custom-radio-and-checkbox/
simple code:
<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">
simple head:
$(document).ready(function(){
$(".radio").dgStyle();
$(".checkbox").dgStyle();
});
if i add to $(document).ready , after ($".checkbox").dgStyle(); The following:
alert($('input:radio[name=shipping]:checked').val());
it works fine!
but - if i do something like that, it is not working:
$(function() {
$("input:radio[name=shipping]:checked").change(function() {
alert("123");
});
});
i tried to remove :checked, still not working.
- maybe you know different jquery custom buttons in that same colors, which can does it..?
- 1 Works fine for me: jsfiddle/vsk3V – epascarello Commented Dec 30, 2012 at 16:20
- do you want it like this? jsfiddle/ds4Qg/2 – Netorica Commented Dec 30, 2012 at 16:21
- i got into conclusion that because i use a custom styled radio, i can't call change() function. if i remove the custom radio, it works fine. do you know a way to pass through it? or perhaps another way to make custom buttons which i can actually see their change. thanks! – user1936192 Commented Dec 30, 2012 at 16:43
- OMG! its a div! and not really a checkbox or radio button.. – Netorica Commented Dec 30, 2012 at 16:46
- really? weird... you know what i can do about it anyway? – user1936192 Commented Dec 30, 2012 at 16:51
2 Answers
Reset to default 6Ok, I got this:
$(".radio").click(function() {
alert('ID : ' + $(this).find('input:radio').prop('id'));
alert('Value : ' + $(this).find('input:radio').prop('value'));
});
DEMO HERE
You must remove the :checked
on the selector
$(function() {
$("input:radio[name=shipping]").change(function() {
alert('123');
});
});
Demo
NOTE: please make sure you don't use same ID's on your elements its really a bad practice or else you will face a lot of issues
本文标签: javascriptjquery get radio value on changeStack Overflow
版权声明:本文标题:javascript - jquery get radio value on change - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741335212a2373001.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论