javascript 从 jquery 对象中获取 HTML 元素的类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14587289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:01:53 来源:igfitidea点击:
Get the type of the HTML element from a jquery object
提问by benVG
Possible Duplicate:
Get element type with jQuery
可能的重复:
使用 jQuery 获取元素类型
Preamble: I'm Italian, sorry for my bad English.
序言:我是意大利人,抱歉我的英语不好。
From an html code like this:
从这样的 html 代码:
<input class="myElem" />
<input class="myElem" />
<div class="myElem"></div>
<ul class="myElem"></ul>
<input class="myElem" />
is there a way to retrieve the html objects type?
有没有办法检索 html 对象类型?
something like:
就像是:
$('.myElem').each(function () {
var htmlType = $(this).type() //Example
console.log(htmlType);
});
/* Log:
* input
* input
* div
* ul
* input
*/
回答by dmk
$('.myElem').each(function () {
var htmlType = $(this).prop('tagName') //Example
console.log(htmlType);
});