久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='qKoT8'><tr id='qKoT8'><dt id='qKoT8'><q id='qKoT8'><span id='qKoT8'><b id='qKoT8'><form id='qKoT8'><ins id='qKoT8'></ins><ul id='qKoT8'></ul><sub id='qKoT8'></sub></form><legend id='qKoT8'></legend><bdo id='qKoT8'><pre id='qKoT8'><center id='qKoT8'></center></pre></bdo></b><th id='qKoT8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qKoT8'><tfoot id='qKoT8'></tfoot><dl id='qKoT8'><fieldset id='qKoT8'></fieldset></dl></div>
  • <legend id='qKoT8'><style id='qKoT8'><dir id='qKoT8'><q id='qKoT8'></q></dir></style></legend>

    <small id='qKoT8'></small><noframes id='qKoT8'>

      <bdo id='qKoT8'></bdo><ul id='qKoT8'></ul>

    1. <tfoot id='qKoT8'></tfoot>
      1. 使用jQuery獲取元素的所有屬性

        Get all attributes of an element using jQuery(使用jQuery獲取元素的所有屬性)
        • <legend id='LbNms'><style id='LbNms'><dir id='LbNms'><q id='LbNms'></q></dir></style></legend>

              <tbody id='LbNms'></tbody>
              • <bdo id='LbNms'></bdo><ul id='LbNms'></ul>

                <small id='LbNms'></small><noframes id='LbNms'>

                <i id='LbNms'><tr id='LbNms'><dt id='LbNms'><q id='LbNms'><span id='LbNms'><b id='LbNms'><form id='LbNms'><ins id='LbNms'></ins><ul id='LbNms'></ul><sub id='LbNms'></sub></form><legend id='LbNms'></legend><bdo id='LbNms'><pre id='LbNms'><center id='LbNms'></center></pre></bdo></b><th id='LbNms'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LbNms'><tfoot id='LbNms'></tfoot><dl id='LbNms'><fieldset id='LbNms'></fieldset></dl></div>
                  <tfoot id='LbNms'></tfoot>

                  本文介紹了使用jQuery獲取元素的所有屬性的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在嘗試遍歷一個元素并獲取該元素的所有屬性以輸出它們,例如,一個標(biāo)簽可能有 3 個或更多屬性,我不知道,我需要獲取這些屬性的名稱和值.我的想法是這樣的:

                  $(this).attr().each(function(index, element) {var name = $(this).name;var 值 = $(this).value;//用名稱和值做一些事情...});

                  誰能告訴我這是否可行,如果可行,正確的語法是什么?

                  解決方案

                  attributes 屬性包含所有這些:

                  $(this).each(function() {$.each(this.attributes, function() {//this.attributes 不是一個普通的對象,而是一個數(shù)組//屬性節(jié)點(diǎn),包含名稱和值如果(this.specified){console.log(this.name, this.value);}});});

                  <小時>

                  您還可以做的是擴(kuò)展 .attr 以便您可以像 .attr() 一樣調(diào)用它來獲取所有屬性的普通對象:

                  (函數(shù)(舊) {$.fn.attr = 函數(shù)() {if(arguments.length === 0) {如果(this.length === 0){返回空值;}變量 obj = {};$.each(this[0].attributes, function() {如果(this.specified){obj[this.name] = this.value;}});返回對象;}返回 old.apply(this, arguments);};})($.fn.attr);

                  用法:

                  var $div = $("

                  I am trying to go through an element and get all the attributes of that element to output them, for example an tag may have 3 or more attributes, unknown to me and I need to get the names and values of these attributes. I was thinking something along the lines of:

                  $(this).attr().each(function(index, element) {
                      var name = $(this).name;
                      var value = $(this).value;
                      //Do something with name and value...
                  });
                  

                  Could anyone tell me if this is even possible, and if so what the correct syntax would be?

                  解決方案

                  The attributes property contains them all:

                  $(this).each(function() {
                    $.each(this.attributes, function() {
                      // this.attributes is not a plain object, but an array
                      // of attribute nodes, which contain both the name and value
                      if(this.specified) {
                        console.log(this.name, this.value);
                      }
                    });
                  });
                  


                  What you can also do is extending .attr so that you can call it like .attr() to get a plain object of all attributes:

                  (function(old) {
                    $.fn.attr = function() {
                      if(arguments.length === 0) {
                        if(this.length === 0) {
                          return null;
                        }
                  
                        var obj = {};
                        $.each(this[0].attributes, function() {
                          if(this.specified) {
                            obj[this.name] = this.value;
                          }
                        });
                        return obj;
                      }
                  
                      return old.apply(this, arguments);
                    };
                  })($.fn.attr);
                  

                  Usage:

                  var $div = $("<div data-a='1' id='b'>");
                  $div.attr();  // { "data-a": "1", "id": "b" }
                  

                  這篇關(guān)于使用jQuery獲取元素的所有屬性的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                  anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項(xiàng)目中不起作用)
                  Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數(shù)據(jù)更新 Observable)
                  Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                  In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創(chuàng)建使用 Ionic 組件的自定義指令?)
                  Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態(tài)元素 - Angular 2 amp;離子2)
                    <legend id='ugpjF'><style id='ugpjF'><dir id='ugpjF'><q id='ugpjF'></q></dir></style></legend><tfoot id='ugpjF'></tfoot>
                  1. <small id='ugpjF'></small><noframes id='ugpjF'>

                          <tbody id='ugpjF'></tbody>
                        • <i id='ugpjF'><tr id='ugpjF'><dt id='ugpjF'><q id='ugpjF'><span id='ugpjF'><b id='ugpjF'><form id='ugpjF'><ins id='ugpjF'></ins><ul id='ugpjF'></ul><sub id='ugpjF'></sub></form><legend id='ugpjF'></legend><bdo id='ugpjF'><pre id='ugpjF'><center id='ugpjF'></center></pre></bdo></b><th id='ugpjF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ugpjF'><tfoot id='ugpjF'></tfoot><dl id='ugpjF'><fieldset id='ugpjF'></fieldset></dl></div>
                          • <bdo id='ugpjF'></bdo><ul id='ugpjF'></ul>
                            主站蜘蛛池模板: 91成人在线视频 | www.九色 | 国产福利网 | 黄色免费av | 天天射一射 | av不卡一区| 欧美综合一区二区 | 正在播放国产精品 | 欧美日韩国产激情 | 91成人精品一区在线播放 | 国产在线二区 | 91麻豆精品国产 | 欧美精品一二三区 | 日本午夜精品 | 国产精品三 | 一区二区三区在线观看视频 | 国产成人在线观看免费网站 | 九九在线视频 | 三上悠亚激情av一区二区三区 | 超碰成人网 | www.黄色com | 综合久久99 | 五月激情久久 | av中文在线 | 亚洲精品免费在线 | 国产综合久久 | 成人福利在线观看 | 亚洲免费网站 | 色综合五月 | 日韩综合精品 | 亚洲第一综合 | av免费网| 日韩 欧美 亚洲 | 成人做爰69片免费 | 久久理论片 | 国产一区二区三区久久 | 久久久久久亚洲精品 | 欧美一级网站 | 国产黄色免费 | 精品视频在线播放 | 青久久 |