Gre*_*g G 2 javascript jquery scope
我有一个函数,我在另一个函数中调用.它返回一个名为"checked"的变量,但该名称不是全局的,并且仅在该函数的范围内.
我的另一个函数有自己的局部变量叫做'checked',但是当我尝试将它设置为1时,它总是返回0.
我发现如果我删除函数调用我的第一个函数,它然后得到正确的值.
当两个变量的范围对于它们所处的函数是局部的时,这怎么可能呢?
function filterRadioCheck()
{
checked = 0;
$('#filterType').children('input').each(function() {
if ($(this).attr('checked'))
{
checked = $(this).attr('value');
}
});
return checked;
}
function setTagDefaultMode()
{
checked = 1;
radiocheck = filterRadioCheck();
//******'checked' is always 0 after this point*****///
// alert(checked) will return 0 even though checked it is set to 1 above;
}
Run Code Online (Sandbox Code Playgroud)