jQuery根據(jù)表單name獲取值的方法

字號:


    這篇文章主要介紹了jQuery根據(jù)表單name獲取值的方法,總結(jié)分析了jQuery獲取表單值的常用技巧,涉及jQuery選擇器的使用技巧,非常簡單實(shí)用,需要的朋友可以參考下
    本文實(shí)例講述了jQuery根據(jù)表單name獲取值的方法。分享給大家供大家參考,具體如下:
    根據(jù)name取值:
    $("input[name='mobile']").val()
    根據(jù)id取值:
    $("#mobile_reg_form").html()
    根據(jù)name取值遍歷:
    $("input[name='mobile']").each(
    function(){
    alert($(this).val());
    }
    )
    取出form中的input:
    <script type="text/javascript" language="JavaScript" charset="UTF-8">
    $(document).ready(function(){
    var a=$("form input");
    $.each(
      a,
    function(name,object){
    alert(name+":"+$(object).val());
    }
    );
    });
    </script>
    得到值(多個(gè)的情況):
    $("input[name='mobile']")[0].value
    $("input[name='mobile']").get(1).value
    jquery添加刪除樣式
    給一個(gè)標(biāo)簽添加樣式:
    $("#id").addClass("style");
    刪除一個(gè)標(biāo)簽的樣式:
    $("#id").removeClass("style");
    注:"#id"  id是對應(yīng)標(biāo)簽的id,style是對應(yīng)css樣式的名稱
    希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。