jQuery的is()函数的替代方法? [英] Alternative for jQuery's is() function?

查看:134
本文介绍了jQuery的is()函数的替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery的.is()函数(在1.6中引入的函数,而不是它的先前版本)比较对象,但是很遗憾,它无法与jQuery 1.5.2一起使用. .我想知道是否可以使用某种替代方法?

I was using jQuery's .is() function (the one introduced in 1.6, not the prior version of it) to compare an object, but it unfortunately won't work with jQuery 1.5.2, which is what I am using. I'm wondering if there is some kind of alternative that I can use?

我正在考虑克隆每个对象然后进行比较,但这似乎并不是实现此目的的最佳方法.

I'm thinking of cloning each object and then comparing it, but this doesn't seem like the best way to do this.

                $('#js-show-more-toggle').contents().each(function() {
                if (seen) {
                    $wrapper.append(this);
                } else if ($(this).is($marker)) {
                    // This is what we want to show
                    seen = true;
                }
            }).end().append($wrapper, $more);

jsfiddle: http://jsfiddle.net/someprimetime/n4jnr/14/

jsfiddle : http://jsfiddle.net/someprimetime/n4jnr/14/

推荐答案

您可以使用this === $marker[0]比较两个DOM元素.

You can use this === $marker[0] to compare the two DOM elements.

尽管如此,请考虑升级到最新的jQuery版本.除了一些小的更改,通常很容易.

Consider upgrading to a recent jQuery version though. Except some minor changes it's usually pretty easy.

这篇关于jQuery的is()函数的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆