亚洲AV无码乱码在线观看性色,免费无码又爽又刺激高潮视频,用你的指尖扰乱我下一部动漫,人妻AV中文系列,人妻熟妇女的欲乱系列

js如何給dom對(duì)象綁定方法

時(shí)間:2023-06-01 22:43:55 類型:JS/JQUERY
字號(hào):    

如果我們想給所有的dom對(duì)象都綁定一個(gè)方法,比如綁定一個(gè)css方法,傳遞對(duì)象屬性,可以修改屬性,該如何綁定呢?

這里給一個(gè)實(shí)例做法

<div class="test">秀了嗎</div>
<div class="t1">我的國(guó)</div>

js代碼:

 HTMLElement.prototype.css= function(){
                    // console.log(arguments[0]);
                    let str = ''
                    if(typeof(arguments[0])=='object'){
                        console.log(11);
                        for (const key in arguments[0]) {
                        str += `${key}:${arguments[0][key]};`
                        //console.log(str);
                        }
                    }else{
                        str = arguments[0]+':' +arguments[1]+';';
                    }
                    console.log(str);
                    this.style = str;
                }
       const t = document.querySelector(".test")
       t.css({'font-Size':'28px',color:'blue'})
       const t1 = document.querySelector(".t1")
       t1.css({'font-Size':'58px',color:'red'})


<