欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

jquery 监听radio选中,取值 click 有大用

google 谷歌  "jquery radio change event"

监听点击事件,根据不同值做不同回应

 

1
var discount=$("input[name=discount]:checked").val();

 

alert($('input[name="button0[wx_menu_type_booltype]"]:checked').val());
alert($("input[name='button0[wx_menu_type_booltype]']:checked").val());


获取当前选中的radio的值

jquery 监听radio选中,取值


<input type="radio" name="bedStatus" id="allot" checked="checked" value="allot">Allot 

<input type="radio" name="bedStatus" id="transfer" value="transfer">Transfer

正确答案
$(document).ready(function()
{
      $('input[type=radio][name=bedStatus]').change(function()
      //$("input[type='radio'][name='bedStatus']").change(function()  //这个肯定是可以的,因为自己亲自做的
      {
          if (this.value == 'allot')
          {
               alert("Allot Thai Gayo Bhai");
         }
         else if (this.value == 'transfer')
         {
            alert("Transfer Thai Gayo");
         }
     });
});

来自 http://stackoverflow.com/questions/13152927/how-to-use-radio-on-change-event



<input type="radio" name="testGroup" id="test1" />test1<br/>

        <input type="radio" name="testGroup" id="test2" />test2<br/>
        <input type="radio" name="testGroup" id="test3" />test3</br>



$(function(){ $('input:radio').change( function(){ alert('changed'); } ); });

$(document).ready(function(){


    $("input[name=discount]").each(function(){

        $(this).click(function(){

            var discount = $(this).val();

            if(discount=="0"){

                $(".discount").css("display","none");

            }

            if(discount=="1"){

                $(".discount").css("display","inline");

            }

        });

    });

});

监听点击事件,根据不同值做不同回应

 

1
var discount=$("input[name=discount]:checked").val();

 获取当前选中的radio的值

jquery 监听radio选中,取值

来自 http://www.it610.com/article/1807239.htm


 

 

今天做项目遇到一个问题,就是如何通过JQuery选中radio,网上大部分都是像下边这样解决的
js代码
1
2
3
4
5
6
通过name
$("input:radio[name="analyfsftype"]").eq(0).attr("checked",'checked');
$("input:radio[name="analyshowtype"]").attr("checked",false);
通过id
$("#tradeType0").attr("checked","checked");
$("#tradeType1").attr("checked",false);

 但是通过验证发现,这些解决方法行不通,于是自己有硬着头皮纠缠了1个小时,终于找到最终解决办法了,那就是下面的做法
js代码
1
$("input:radio[name="analyfsftype"]").eq(0).click();
 

来自  http://www.edbiji.com/doccenter/showdoc/5/nav/769.html


jquery监听radio,当选择一个就触发函数,遇到的问题及解决方案  

2013-07-03 16:33:29|  分类: js|举报|字号 订阅

  

<input type="radio" name="cond_result" value="0" />A
<input type="radio" name="cond_result" value="1"/>B

$(function(){
    $("input[name='cond_result']").change(function(){
        var s = $("input[name='cond_result']:checked").val();
        alert("aa is "+ s);
});
问题描述:刚进来,两个radio都是空的,这时候如果选择A,alert不执行,也就是没有触发!
                                                                          如果选择B,立马alert,也就是出发了!
很诡异。。。

想来想去,最终通过加入这样一句,就一直触发了!
<input type="radio" name="cond_result" value="" checked style="display: none"/>
<input type="radio" name="cond_result" value="0" />A
<input type="radio" name="cond_result" value="1"/>B

来自 http://qianzizb.blog.163.com/blog/static/14163922720136343329590/

jquery 监听 radio button选择状态

 
满意 不满意
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
 
复制代码
 1 <html>
 2 <head>
 3 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/JavaScript"></script>
 4    <script type="text/JavaScript">
 5         $(document).ready(function ()
 6         {
 7             $("#needradio :radio").change(function ()
 8             {               
 9                 var value=$(this).val();
10                 if(value==1)
11                 { $("#log").hide();}
12                 else
13                 {$("#log").show();
14                 }                     
15             });
16         });       
17     </script>
18 </head>
19 <body>
20 <div id="needradio">
21     <input type="radio" id="need" name="need" value="1" />满意
22     <input type="radio" id="need" name="need" value="0" />不满意
23 </div>
24 
25     <div id="log">啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊</div>
26  
27 </body>
28 </html>
复制代码

来自 http://www.cnblogs.com/fcq121/archive/2013/05/15/3079286.html

普通分类: