变量未在.each(function()循环内传递

时间:2017-03-13 04:46:55

标签: javascript jquery loops variables scope

为什么变量路径在undefined循环中显示为.each

function tt(xml, path) {
    var tree = new Array();
    console.log('path=' + path); // This output as 'path = abc' -- ok

    $(xml).contents().each(function() {
        console.log('path=' + path); //this output as 'path=undefined' ??

        //do something with xml
    });
}

tt(x, 'abc');

0 个答案:

没有答案