[jquery ajax]jquery 获取radio属性值方法

时间:2016-12-04  来源:jquery  阅读:

核心代码

$("div.child :radio:checked",$(this).parents("div")).val()

有专门的选择器:first可以选中第一个,也可以通过$().eq(1)选中第一个。
jquery功能强大,而且选择同一元素可以使用若干种选择方式。。

对于radio的选中,虽然不直接支持,但是也有两个方式。
$(radio).attr("selected",true);
或$(radio).click(function(){});


下面看实例


        1
        2
        3
        4
        5
       
       
   

 

 <script language="网页特效" type="text/javascript">
//

        function button1_onclick() {
            $("input").each(function () {
                if (this.type == "radio") {
                    alert($(this).val());
                }
            });
        }

        function button2_onclick() {
            //alert($("input[@type=radio]:checked").val());
            //alert($("input[name="rad"]:checked").val());
            alert($("input[@type=radio]").val());
        }

// ]]>
    </script>


代码二

 

<script type="text/javascript" src="jquery.js">
    </script>
     <script type="text/javascript">
         $(function(){
             $("#form1").submit(function(){
                 var item = $("input[@name=items][@checked]").val();
                 alert(item);
                 return false;
             });
         });
     </script>
     get radio value document


    

         a
        

         b
        

         c
        

         d
        

         e
        

         f
        

         g
        

         h
        

        
    


$("div.child").closest("div")

如果你无法判断怎么选择的话,加个id就行了,你应该知道就是优先的方式,因为id是查询最快的方式,而通过.class选择是最慢的方式

[jquery ajax]jquery 获取radio属性值方法

http://m.bbyears.com/wangyezhizuo/28753.html

推荐访问:jquery获取select选中的值
相关阅读 猜你喜欢
本类排行 本类最新