日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 芯聞號(hào) > 充電吧
[導(dǎo)讀]設(shè)置與獲取為同一個(gè)方法,不傳入?yún)?shù)為獲取,傳入?yún)?shù)為設(shè)置 input元素value:val方法 button //設(shè)置input的value $("#edittex

設(shè)置與獲取
    //設(shè)置input的value
    $("#edittext").val("99");
    //獲取input的value
    var ret = $("#edittext").val();
    console.log(ret);


常規(guī)元素text:html方法

hello

hello

    //設(shè)置a標(biāo)簽的text
    $(".a").html("99");
    //獲取a標(biāo)簽的text
    var     ret = $(".a").html();
    console.log(ret);

    //設(shè)置p元素的text
    $(".p").html("pppppp");
    //獲取a元素的text
    ret = $(".p").html();
    console.log(ret);
樣式表:css方法 css(屬性,值)
    var $obj =$(".a");
    //設(shè)置css的color屬性
    $obj.css("color","red"); 

    //獲取css的color屬性 color類型返回 rgb(255,0,0) 類型string
    var m_color = $obj.css("color");
    console.log(m_color+"類型:"+typeof m_color);

迭代:


    var $obj =$(".a");


    for(var x=0;x<$obj.length;x++)
    {
        $obj.eq(x).html("im index:"+x);

    }

    $obj= $(".a");//可省略 前面已經(jīng)得到


    for(var x=0;x<$obj.length;x++)
    {
        console.log($obj.eq(x).html());

    }




具體可查看jQuery var函數(shù)實(shí)現(xiàn)
val: function( value ) {
        var hooks, ret, isFunction,
            elem = this[ 0 ];

        if ( !arguments.length ) {
            if ( elem ) {
                hooks = jQuery.valHooks[ elem.type ] ||
                    jQuery.valHooks[ elem.nodeName.toLowerCase() ];

                if (
                    hooks &&
                    "get" in hooks &&
                    ( ret = hooks.get( elem, "value" ) ) !== undefined
                ) {
                    return ret;
                }

                ret = elem.value;

                return typeof ret === "string" ?

                    // handle most common string cases
                    ret.replace( rreturn, "" ) :

                    // handle cases where value is null/undef or number
                    ret == null ? "" : ret;
            }

            return;
        }

        isFunction = jQuery.isFunction( value );

        return this.each( function( i ) {
            var val;

            if ( this.nodeType !== 1 ) {
                return;
            }

            if ( isFunction ) {
                val = value.call( this, i, jQuery( this ).val() );
            } else {
                val = value;
            }

            // Treat null/undefined as ""; convert numbers to string
            if ( val == null ) {
                val = "";
            } else if ( typeof val === "number" ) {
                val += "";
            } else if ( jQuery.isArray( val ) ) {
                val = jQuery.map( val, function( value ) {
                    return value == null ? "" : value + "";
                } );
            }

            hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];

            // If set returns undefined, fall back to normal setting
            if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
                this.value = val;
            }
        } );
    }
本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉