gpt4 book ai didi

javascript - 返回元素类型

转载 作者:行者123 更新时间:2023-11-30 13:17:01 27 4
gpt4 key购买 nike

是否可以返回元素类型?我想在没有 class 属性的情况下将类的样式添加到 HTML5 对象。

   <!DOCTYPE>
<html>
<head>
<title>My page</title>
</head>
<body>
<header>
Hello World
</header>
<section>
Another object
</section>
</body>
<!-- jQuery if need be -->
<script>
$("body>*").each(function(){
alert($(this).object());
// Would alert "header" and "section"
});
</section>
</html>

最佳答案

您可以使用 .tagName :

$("body>*").each(function(){
alert(this.tagName);
});

Live demo

关于javascript - 返回元素类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11689835/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com