jquery获取值传值

1。

     $("input[name='uname']").val();

 

2。*

       var types=[]; 

       $('input[name="types"]:checked').each(function(){ 
            types.push($(this).val()); 

       }); 

     ajax({

         type:"post',

         url:"#",

         traditional :true,//必须加上该句话来序列化  (不然后台的键值名字是types[]:)

         data:{"types":types},

         success:function(){}

    })

    复选框的全选,取消

    $("allbtn").click(function(){

         $(this).parent.find("input: checkbox").prop("checked",true);

    })

    $("cancelbtn").click(function(){

         $(this).parent.find("input: checkbox").prop("checked",false);

    })

 

  • 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法。
  • 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法。

 

3。

     var types=$("[name='types'] option:selected").val();

     获取下拉框的下标:selectedIndex

     var index=$("[name='types']")[0].selectedIndex;

     移除下拉选择下标0后面的所有:$("#types").find("option:gt(0)").remove();

 

4。

     var on=$("input[name='on']:checked ").val();

 

5。

     //用英文逗号分隔开传值

     var contents=$("#content").val();

     contents=contents.replace(/,/ig,',');

     var arr=contents.split(",");

     for(var i=0;i

         var arrs=arr[i]

     }

 

你可能感兴趣的:(jquery获取值传值)