简体   繁体   English

如何从JQuery对象获取javascript控件?

[英]How to get javascript control from JQuery object?

I'm a beginner in JQuery, 我是JQuery的初学者,

How can I get the control as a javascript object from a JQuery object 如何从JQuery对象将控件作为javascript对象获取

var _object = $(this). ??

Most common var _object = $(this)[0]; 最常见的var _object = $(this)[0];

If you have more than 1 elements matched: $(this)[0] , $(this)[1] , $(this)[2] and so on. 如果匹配的元素超过1个: $(this)[0]$(this)[1]$(this)[2]等等。

$(this).get() is also possible. $(this).get()也是可能的。 It's only advantage over the array model is that it allows selection of the kind $(this).get(-1) where it gets you the last matched object 它比数组模型的唯一优势是它允许选择类型$(this).get(-1) ,它可以获得最后一个匹配的对象

(function (e) {
    var a = false;
    try {
        $(this)[0];
        a = true;
    } catch (h) {}
    alert(a.toString());
})(window);
var _object = $(this)[0];

我认为这是对的,不能检查,因为我在我的手机上。

In your case, simply use this . 在您的情况下,只需使用this

$(this)[0] == this if this is a DOM element. $(this)[0] == this如果this是一个DOM元素。 If it's something else, eg a selector, $(this)[0] is the way to go. 如果它是其他东西,例如选择器, $(this)[0]是要走的路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM