0

<script</script我对javascript很陌生,当我遇到这个错误时我正在练习,当位置变量在标签内时,我的网络浏览器找不到html文档

<script>
<!--

    var location = "Syrdsase va";
    var name = "bob sixlet";
    var age = 14;

    document.write(name + ", " + age + location);

//-->
</script>
4

2 回答 2

2

juste 不要使用位置作为变量,它会将您重定向到新页面。更改您的变量名称,它将起作用

js中的一些保留变量 http://www.quackit.com/javascript/javascript_reserved_words.cfm

于 2013-08-03T10:31:21.437 回答
1

有一个location对象在分配时会更改页面的位置:

location = 'http://www.google.com'; // goes to Google homepage

通常,为了避免混淆,它通常被称为 using window.location,但由于window它只是全局对象,因此重新分配location将使页面转到作为字符串值的 URL。

要解决此问题,只需重命名变量:

var myLocation = "Syrdsase va";

var name = "bob sixlet";

var age = 14;

document.write(name + ", " + age + myLocation);
于 2013-08-03T10:27:30.090 回答