我知道我可能做错了什么。任何人都可以指出为什么我会成为对象吗??
$(document).ready(function(){
topwithpx='0px';
alert(topwithpx);
topstr=topwithpx.substr(0,topwithpx.length-2);
alert(topstr);
top=parseInt(topstr);
alert(top);
});
谢谢大家:'top' 是保留关键字 (Window.top)。我的错。接受第一个答案。 +1 给所有人快速回答。
最佳答案
因为它本质上是 window.top
,即 Window object .使用 var top
来防止混合局部变量和全局变量(= window
对象的属性)。
事实上,让 var
-ing 您的函数变量成为一种常见的例程 - 以防止将来出现类似的问题。 )
关于javascript - JS parseInt() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12093615/