【问题标题】:jquery - check the type of the elementjquery - 检查元素的类型
【发布时间】:2011-08-12 22:41:14
【问题描述】:

如何确定元素的类型?

例如,我有一个函数,它与具有特定类的所有元素挂钩。这些元素可以是 textareas、iframe、div 等。我想知道当前是哪种元素。

【问题讨论】:

    标签: javascript jquery html jquery-selectors


    【解决方案1】:

    使用Element Selector 获取特定类型元素。

    并使用 tagName 来获取特定元素的类型。

    How can I determine the element type of a matched element in jQuery?

    【讨论】:

      【解决方案2】:

      这里有一些工作example

      HTML:

      <span class="some"></span>
      <div class="some"></div>
      

      jQuery:

      $('.some').each( function ( index ) {
          document.write(index + ':' + $(this).attr("tagName").toLowerCase() + '<br/>');
      });
      

      【讨论】:

        【解决方案3】:

        你可以调用 attr("tagName"):

        $("a").attr("tagName");
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2010-10-11
          • 2019-05-10
          • 1970-01-01
          • 2013-07-13
          • 2011-01-20
          • 1970-01-01
          相关资源
          最近更新 更多