<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        HTML中的attribute和property_html/css

        來源:懂視網 責編:小采 時間:2020-11-27 16:08:59
        文檔

        HTML中的attribute和property_html/css

        HTML中的attribute和property_html/css_WEB-ITnose:一、概述 attribute和property是常常被弄混的兩個概念。 簡單來說,property則是JS代碼里訪問的: document.getElementByTagName('my-element').prop1 = 'hello'; attribute類似這種: JS代碼里訪問attribute的方式是getAttr
        推薦度:
        導讀HTML中的attribute和property_html/css_WEB-ITnose:一、概述 attribute和property是常常被弄混的兩個概念。 簡單來說,property則是JS代碼里訪問的: document.getElementByTagName('my-element').prop1 = 'hello'; attribute類似這種: JS代碼里訪問attribute的方式是getAttr

        一、概述

        attribute和property是常常被弄混的兩個概念。

        簡單來說,property則是JS代碼里訪問的:

        document.getElementByTagName('my-element').prop1 = 'hello';

        attribute類似這種:

        JS代碼里訪問attribute的方式是getAttribute和setAttribute:

        document.getElementByTagName('my-element').setAttribute('attr1','Hello');

        document.getElementByTagName('my-element').getAttribute('attr1','Hello');

        二、區別

        多數情況下,兩者是等效的。在web標準中,常常會規定某attribute“反射”了同名的property。但是例外的情況還是不少的。

        1. 名字不一致

        最典型的是className,為了回避JavaScript保留字,JS中跟class attribute對應的property是className。

        //若value屬性已經設置,則attribute不變,property變化,元素上實際的效果是property優先

        input.value //hello

        input.getAttribute('value'); //cute

        除此之外,checkbox的顯示狀態由checked和indeterminate兩個property決定,而只有一個名為checked的property,這種情況下property是更完善的訪問模型。

        三、特殊場景

        1.mutation

        使用mutation observer,只能監測到attribute變化。

        var observer = new MutationObserver(function(mutations){

        for(var i = 0; i < mutations.length; i++) {

        var mutation = mutations[i];

        console.log(mutation.attributeName);

        }

        });

        observer.observe(element,{attributes:true});

        element.prop1 = 'aa' // 不會觸發

        element.setAttribute('attr1', 'aa') //會觸發

        2.custom element

        在使用WebComponents時,可以定義attribute和property,兩者可以互相反射,也可以全無關聯。

        var MyElementProto = Object.create(HTMLElement.prototype, {

        createdCallback : {

        value : function() { }

        }

        });

        //定義property

        Object.defineProperty(MyElementProto,'prop1', {

        get:function(){

        return //

        },

        set:function(){

        console.log('property change');//do something

        }

        });

        //定義attribute

        MyElementProto.attributeChangedCallback = function(attr, oldVal, newVal) {

        if(attr === 'attr1') {

        console.log('attribute change');//do something

        }

        };

        window.MyElement = document.registerElement('my-element', {

        prototype: MyElementProto

        });

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        HTML中的attribute和property_html/css

        HTML中的attribute和property_html/css_WEB-ITnose:一、概述 attribute和property是常常被弄混的兩個概念。 簡單來說,property則是JS代碼里訪問的: document.getElementByTagName('my-element').prop1 = 'hello'; attribute類似這種: JS代碼里訪問attribute的方式是getAttr
        推薦度:
        標簽: pr it html
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲人成网址在线观看| 亚洲成?Ⅴ人在线观看无码| 91精品国产亚洲爽啪在线影院| 久久国产精品免费一区| 国产亚洲色婷婷久久99精品91| 日亚毛片免费乱码不卡一区 | 日韩激情淫片免费看| 亚洲第一男人天堂| 好男人视频在线观看免费看片| 亚洲精品一二三区| 午夜视频在线在免费| 国内成人精品亚洲日本语音| 免费国产真实迷j在线观看| 四虎一区二区成人免费影院网址| 亚洲国产专区一区| 国产在线观看xxxx免费| 亚洲Av无码精品色午夜| 九九精品免费视频| jizzjizz亚洲日本少妇| 久久影院亚洲一区| 97国产在线公开免费观看| 亚洲人成图片网站| 亚洲国产中文字幕在线观看 | 久久精品国产亚洲AV忘忧草18| 成年性午夜免费视频网站不卡| 色天使色婷婷在线影院亚洲| 久久久青草青青国产亚洲免观| 在线播放免费人成毛片乱码| 亚洲理论片在线观看| 在线免费观看韩国a视频| a级毛片视频免费观看| 亚洲一区二区久久| 亚洲精品视频在线看| 香蕉免费一区二区三区| 亚洲最大的成人网站| 久久精品亚洲乱码伦伦中文| 四虎精品视频在线永久免费观看| 亚洲爆乳无码精品AAA片蜜桃| 亚洲精品二区国产综合野狼| 免费看国产成年无码AV片| 免费在线观看自拍性爱视频|