在脚本标记中,为了检索变量内部的变量值,我已经使用了下面的代码,但是它没有返回任何值。变量javascript中的变量
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script type="text/javascript" language="javascript">
$(function() {
var data = {
GetAnimals: function()
{
return 'tiger'; assign value to GetAnimals variable
},
GetBirds:function()
{
return 'pegion'; assign value to GetBirds variable
}
}
});
document.write(data.GetAnimals);//should print tiger
document.write(data.GetAnimals);//should print pegion
</script>
但是,我无法打印所需的结果。
在此先感谢。
我猜'数据'有局部范围? – NINCOMPOOP