【问题标题】:Get the type of the HTML element from a jquery object [duplicate]从 jquery 对象中获取 HTML 元素的类型 [重复]
【发布时间】:2013-01-13 06:46:22
【问题描述】:

可能重复:
Get element type with jQuery

序言:我是意大利人,抱歉我的英语不好。

来自这样的 html 代码:

<input class="myElem" />
<input class="myElem" />
<div class="myElem"></div>
<ul class="myElem"></ul>
<input class="myElem" />

有没有办法检索 html 对象类型?

类似:

$('.myElem').each(function () {
      var htmlType = $(this).type() //Example
      console.log(htmlType);
});

/* Log:
*    input
*    input
*    div
*    ul
*    input
*/

【问题讨论】:

    标签: javascript jquery html types


    【解决方案1】:
    $('.myElem').each(function () {
          var htmlType = $(this).prop('tagName') //Example
          console.log(htmlType);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多