什么是'$(本)及"x27 ;;包含在下面的javascript函数代码中?

什么是'$(本)及"x27 ;;包含在下面的javascript函数代码中?,javascript,jquery,function,this,alert,Javascript,Jquery,Function,This,Alert,以下是函数的代码: $Core.notification = { bDebug: false, update: function() { setTimeout('$.ajaxCall("notification.update", "", "GET");', 1000); }, setTitle: function() { var iTotal = 0; var sTitle = $('tit

以下是函数的代码:

$Core.notification =
{   
    bDebug: false,

    update: function()
    {
        setTimeout('$.ajaxCall("notification.update", "", "GET");', 1000);
    },

    setTitle: function()
    {
        var iTotal = 0;
        var sTitle = $('title').html();

        $('.holder_notify_count').each(function(){ alert($(this));
            iTotal += parseInt($(this).html());
        });

        var newTitle = '';      
        var aMatches = sTitle.match(/(\([0-9]*\))/i);
        if (aMatches !== null && isset(aMatches[1])){
            if (iTotal > 0){
                newTitle = '(' + iTotal + ') ' + sTitle.replace(aMatches[1], '');
                //$('title').html(newTitle.replace('#',''));
                // document.title = newTitle.replace('#', '');
            }
            else{
                //$('title').html(aMatches[1].replace('#',''));
                // document.title = aMatches[1].replace('#', '');
            }
        }
        else{
            if (iTotal > 0){
                //$('title').prepend('(' + iTotal + ') '); // it doesnt work in IE8
                // ie8 doesnt like hashes           
                var NewTitle = document.title.replace('#','');              
                // document.title = '(' + iTotal + ') ' + NewTitle;

            }
            else{
            }
        }

        if (getParam('notification.notify_ajax_refresh') > 0)
        {
            setTimeout('$.ajaxCall("notification.update", "", "GET");', (this.bDebug ? 10000 : (getParam('notification.notify_ajax_refresh') * 60000)));
        }
    }
};
只考虑上面代码中的以下两行,忽略其余代码:

$('.holder_notify_count').each(function(){
                iTotal += parseInt($(this).html());
            });
我无法理解
$(这个)
包含什么?我尝试了
alert($(this))内部
$('.holder\u notify\u count')。每个(函数(){…})

但是它只打印了
[object object]
,所以我无法找到
$(这个)
包含的内容以及如何打印它

谢谢。

来自

.each()
方法旨在使DOM循环构造简洁且不易出错。调用时,它会迭代作为jQuery对象一部分的DOM元素。每次回调运行时,都会从0开始传递当前循环迭代。更重要的是,回调是在当前DOM元素的上下文中触发的,因此关键字
this
引用该元素

按照你的代码

$('.holder_notify_count').each(function(){

});
回调方法中的此
引用了底层DOM元素
。holder\u notify\u count
From

.each()
方法旨在使DOM循环构造简洁且不易出错。调用时,它会迭代作为jQuery对象一部分的DOM元素。每次回调运行时,都会从0开始传递当前循环迭代。更重要的是,回调是在当前DOM元素的上下文中触发的,因此关键字
this
引用该元素

按照你的代码

$('.holder_notify_count').each(function(){

});
回调方法中的this
引用底层DOM元素
。holder\u notify\u count
$(this)是对象($('.holder\u notify\u count')) $(this).html()表示$('.holder\u notify\u count')中的html。

$(this)是对象($('.holder\u notify\u count')) $(this).html()表示$('.holder\u notify\u count'中的html)

将迭代具有类
.holder\u notify\u count

每个回调中的
$(this)
是一个jQuery对象,包含特定的
DOM
元素
。holder\u notify\u count

它包含在jQuery包装器中,可以访问所有jQuery API调用

将迭代具有类
.holder\u notify\u count

每个回调中的
$(this)
是一个jQuery对象,包含特定的
DOM
元素
。holder\u notify\u count


它包含在jQuery包装器中,可以访问所有jQuery API调用

您在此
循环中迭代的是元素集合中的每个jQuery对象。因此,每个元素都有一个名为
holder\u notify\u count
的类,如jQuery选择器
中所示


这与您将其分配为
$('.holder\u notify\u count')[0]
,然后分配
$('.holder\u notify\u count')[1]
,依此类推。

在此
循环中迭代的是元素集中的每个jQuery对象。因此,每个元素都有一个名为
holder\u notify\u count
的类,如jQuery选择器
中所示


它与您将其分配为
$('.holder\u notify\u count')[0]
,然后
$('.holder\u notify\u count')[1]
等等。

下。each()
警报不起作用。尝试
console.log($(this.html())

下。每个()
警报不起作用。尝试
console.log($(this.html())

Satpal确实给了您正确的答案,但以下是功能分解,以便您更好地理解:

         <ul>
            <li>Hello</li>
            <li>Hello-1</li>
            <li>Hello-2</li>
        </ul>
上述代码将打印以下内容:

"Hello" 
"Hello-1" 
"Hello-2"
为什么?


首先请注意我们是如何选择
$('ul li')
,我们正在选择ul内的所有li,现在每个li将迭代所有li,因此,在第一个iteartion$(这)是secound$上的第一个
li
(这)是第三个$(这)上的secound
li
abd(这)是第三个
li

Satpal给了你正确的答案,但下面是功能分解,让你更好地理解:

         <ul>
            <li>Hello</li>
            <li>Hello-1</li>
            <li>Hello-2</li>
        </ul>
上述代码将打印以下内容:

"Hello" 
"Hello-1" 
"Hello-2"
为什么?


首先请注意我们是如何选择
$('ul li')
,我们正在选择ul内的所有li,现在每个li将迭代所有li,因此,在第一个iteartion$(这)是secound$上的第一个
li
(这)是第三个$(这)上的secound
li
abd(这)第三个
li

@Satpal:但它指的是哪个元素?这是我要问你的问题,它指的是迭代的“当前”元素。每个元素都将
这个
一次。@Satpal:但它指的是哪个元素?这是我要问你的问题,它指的是迭代的“当前”元素。每个元素都将
这个
一次。但它指的是哪个元素?这是我向您提出的问题。@user2839497它指的是
'.holder\u notify\u count'
元素$('.holder\u notify\u count'),但它指的是哪个元素?这是我的问题。@user2839497它指的是
'.holder\u notify\u count'
元素$('.holder\u notify\u count')