jQuery是否有任何功能来确定jQuery对象引用的DOM元素的标签类型? [英] Does jQuery have any function to determine the tag type of the DOM element(s) referenced by jQuery object?
本文介绍了jQuery是否有任何功能来确定jQuery对象引用的DOM元素的标签类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jQuery是否有任何功能来确定jQuery对象引用的DOM元素的标签类型?我正在编写一个jQuery插件和...
Does jQuery have any function to determine the tag type of the DOM element(s) referenced by jQuery object? I am writing a jQuery plugin and...
jQuery.fn.myPlugin() {
return this.each(function() {
var $this = $(this);
// <---------------------------------------HERE!
});
}
我想知道如果这个
是一个< input>
元素或< div>
元素,而不直接使用DOM
I would like to know if this
is an <input>
element or a <div>
element, without directly using the DOM.
推荐答案
执行此操作:
this.nodeName;
...或要安全,将其转换为特定情况:
...or to be safe, convert it to a specific case:
this.nodeName.toLowerCase();
nodeName
属性是一个属性广泛支持,并将为您提供元素节点的标签名称(如你的情况)。
The nodeName
property is a property that is widely supported and will give you the tag name in the case of an element node (as in your case).
这篇关于jQuery是否有任何功能来确定jQuery对象引用的DOM元素的标签类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文