该.first()方法已在jQuery 1.4中添加.
该:first自1.0选择已经存在了.
来自文档:
该
:first伪类相当于:eq(0).它也可以写成:lt(1).虽然这只匹配一个元素,但:first-child可以匹配多个:每个父元素一个.给定一个表示一组DOM元素的
.first()jQuery对象,该方法从第一个匹配元素构造一个新的jQuery对象.
它似乎.first()是一个返回另一个jQuery对象的过滤器,而:first它只是一个选择器.
但是,它们都可以用来完成同样的事情.
那么,何时应该使用一个而不是另一个?性能?请提供示例.
我的网站上有错误:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Timestamp: Fri, 27 Jul 2012 08:54:50 UTC
Message: Unexpected call to method or property access.
Line: 5855
Char: 5
Code: 0
URI: http://garmonia-znakomstva.ru/js/jquery-1.7.2.js
这个jQuery是否与IE8或我的错误不兼容?
打开http://garmonia-znakomstva.ru/时出错
码
这是jQuery代码片段:
prepend: function() {
    return this.domManip(arguments, true, function( elem ) {
        if ( this.nodeType === 1 ) {
5855:           this.insertBefore( elem, this.firstChild );
        }
    });
},
我在jQuery中选择第一个孩子时遇到了一些麻烦.我试图这样做,以避免有很多if语句.基本上,你点击一个按钮.设置此类选择器以处理我的JS中的单击.一旦你进入了JS,我想这是刚刚点击该项目的孩子,但我没有任何喜悦.
这是我在JS中的内容:
$('.itemClicked').click(function(){
var id = $(this).attr('id').first();
    // it can't find the method first() here. If I just find the id, I get the 
    // correct ID of what I just clicked.          
var test = id.first();
    // I tried the above to seperate the ID from the first() method request
    // no joy with this either.
test.toggleClass("icon-tick");
    // this is my ultimate aim, to toggle this icon-tick class on the item
    // clicked.
});
如果你能在这里帮助我,请提前感谢.我可能只是在做一些愚蠢的事情,但我很难意识到这是什么.