pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="rlnqi4i" 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="j5fwgq0" id='LbNms'><tfoot id='LbNms'></tfoot><dl id='LbNms'><fieldset id='LbNms'></fieldset></dl></div>
                  <tfoot id='LbNms'></tfoot>

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

                  問題描述

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

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

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

                  解決方案

                  attributes 屬性包含所有這些:

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

                  <小時>

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

                  (函數(舊) {$.fn.attr = 函數() {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" }
                  

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

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

                  相關文檔推薦

                  Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                  anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                  Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 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 中,如何創建使用 Ionic 組件的自定義指令?)
                  Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - 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="nzcyivj" id='ugpjF'><tfoot id='ugpjF'></tfoot><dl id='ugpjF'><fieldset id='ugpjF'></fieldset></dl></div>
                          • <bdo id='ugpjF'></bdo><ul id='ugpjF'></ul>
                            主站蜘蛛池模板: IP检测-检测您的IP质量 | 淘趣英语网 - 在线英语学习,零基础英语学习网站 | 废气处理设备-工业除尘器-RTO-RCO-蓄热式焚烧炉厂家-江苏天达环保设备有限公司 | 电动百叶窗,开窗器,电动遮阳百叶,电动开窗机生产厂家-徐州鑫友工控科技发展有限公司 | 盘式曝气器-微孔曝气器-管式曝气器-曝气盘-斜管填料 | 郑州市前程水处理有限公司 | 空冷器|空气冷却器|空水冷却器-无锡赛迪森机械有限公司[官网] | 英国雷迪地下管线探测仪-雷迪RD8100管线仪-多功能数字听漏仪-北京迪瑞进创科技有限公司 | 带锯机|木工带锯机圆木推台锯|跑车带锯机|河北茂业机械制造有限公司| | 面粉仓_储酒罐_不锈钢储酒罐厂家-泰安鑫佳机械制造有限公司 | 骨灰存放架|骨灰盒寄存架|骨灰架厂家|智慧殡葬|公墓陵园管理系统|网上祭奠|告别厅智能化-厦门慈愿科技 | 玻纤土工格栅_钢塑格栅_PP焊接_单双向塑料土工格栅_复合防裂布厂家_山东大庚工程材料科技有限公司 | 北京租车公司_汽车/客车/班车/大巴车租赁_商务会议/展会用车/旅游大巴出租_北京桐顺创业租车公司 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 压砖机、液压制砖机、静压砖机、环保砖机生产厂家—杜甫机械 | 缠膜机|缠绕包装机|无纺布包装机-济南达伦特机械设备有限公司 | 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 切铝机-数控切割机-型材切割机-铝型材切割机-【昆山邓氏精密机械有限公司】 | 消泡剂_水处理消泡剂_切削液消泡剂_涂料消泡剂_有机硅消泡剂_广州中万新材料生产厂家 | 拼装地板,悬浮地板厂家,悬浮式拼装运动地板-石家庄博超地板科技有限公司 | 专业生产动态配料系统_饲料配料系统_化肥配料系统等配料系统-郑州鑫晟重工机械有限公司 | 华夏医界网_民营医疗产业信息平台_民营医院营销管理培训 | 专业广州网站建设,微信小程序开发,一物一码和NFC应用开发、物联网、外贸商城、定制系统和APP开发【致茂网络】 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛婚外情取证-青岛王军侦探事务所 | 啤酒设备-小型啤酒设备-啤酒厂设备-济南中酿机械设备有限公司 | 水轮机密封网 | 水轮机密封产品研发生产厂家 | 玻璃瓶厂家_酱菜瓶厂家_饮料瓶厂家_酒瓶厂家_玻璃杯厂家_徐州东明玻璃制品有限公司 | 防火板_饰面耐火板价格、厂家_品牌认准格林雅 | 沉降天平_沉降粒度仪_液体比重仪-上海方瑞仪器有限公司 | 升降机-高空作业车租赁-蜘蛛车-曲臂式伸缩臂剪叉式液压升降平台-脚手架-【普雷斯特公司厂家】 | 博莱特空压机|博莱特-阿特拉斯独资空压机品牌核心代理商 | 便携式XPDM露点仪-在线式防爆露点仪-增强型烟气分析仪-约克仪器 冰雕-冰雪世界-大型冰雕展制作公司-赛北冰雕官网 | 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | 不锈钢列管式冷凝器,换热器厂家-无锡飞尔诺环境工程有限公司 | 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 分光色差仪,测色仪,反透射灯箱,爱色丽分光光度仪,美能达色差仪维修_苏州欣美和仪器有限公司 | 上海乾拓贸易有限公司-日本SMC电磁阀_德国FESTO电磁阀_德国FESTO气缸 | 安驭邦官网-双向万能直角铣头,加工中心侧铣头,角度头[厂家直销] 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | 电镀标牌_电铸标牌_金属标贴_不锈钢标牌厂家_深圳市宝利丰精密科技有限公司 | 全自动五线打端沾锡机,全自动裁线剥皮双头沾锡机,全自动尼龙扎带机-东莞市海文能机械设备有限公司 | 软瓷_柔性面砖_软瓷砖_柔性石材_MCM软瓷厂家_湖北博悦佳软瓷 | 博客-悦享汽车品质生活|