Answers:
改变这个...
var string = document.location;
为此...
var string = document.location + '';
这是因为document.location是一个Location对象。默认.toString()值以字符串形式返回位置,因此串联将触发该位置。
您也可以document.URL用来获取字符串。
toString()而不是强悍的串联会更干净吗?
parseInt()和parseFloat()。也有Number()。的+是当然的较短,但对于某人不用于哈克代码或经验较少的可读性。
+ ''方法在Chrome浏览器中对我来说没有任何变化,但toString()可以。
document.location 不是字符串。
您可能想要使用document.location.href或document.location.pathname代替。
document.location是一个对象。试试:var string=document.location.href