下面显示了以下JavaScript代码:

<script type="text/javascript">

$(document).ready(function() {
     var string = document.location;
     var string2 = string.split('/');
});

</script>

运行此代码时,在Firebug控制台中显示以下错误:

string.split is not a function
var string2 = string.split('/');

造成这个错误的原因是什么?

 

改变这个

var string = document.location;

变成这个

var string = document.location + '';

这是因为document.location是一个Location对象。默认情况下.toString()以字符串形式返回位置,所以连接会触发该位置。

你也可以document.URL用来获取一个字符串。

相关文章:

  • 2021-10-06
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 1970-01-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案