IE 中 Javascript 文件的外部引用
我正在为一位老师开发一个网站, 由于她以后可能想添加更多内容,所以我决定将每个页面上出现的链接都用Javascript编写,以便可以快速更改所有页面。
HTML 代码具有以下内容供外部参考:
<script type="text/javascript" language="javascript" src="links.js"></script>
Javascript 如下所示:
document.write(<div id="wrapper">
<div id="header">
<ul>
<li><a href="home.html">Home </a></li>
<li><a href="catering-home.html">Catering </a></li>
<li><a href="prostart-home.html">ProStart </a></li>
<li><a href="recipes.html">Recipes</a></li>
</ul>
</div>
</div>)
这在 firefox 中完美加载,但由 javascript 编写的页面部分在 IE 中无法加载。是代码的编写方式还是引用阻止了 IE 加载它?
I am working on a website for a teacher,
Since there is a chance she may want to add more later, I decided to make the links that appear on every page be written in by Javascript so that all the pages could be changed quickly.
The HTML code has this for the external reference:
<script type="text/javascript" language="javascript" src="links.js"></script>
The Javascript looks like this:
document.write(<div id="wrapper">
<div id="header">
<ul>
<li><a href="home.html">Home </a></li>
<li><a href="catering-home.html">Catering </a></li>
<li><a href="prostart-home.html">ProStart </a></li>
<li><a href="recipes.html">Recipes</a></li>
</ul>
</div>
</div>)
This loads perfectly in firefox, but the part of the page written in by javascript does not load in IE. is it how the code is written or the reference that is preventing IE from loading it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要像这样在它周围加上引号:
但是,如果它只是在 HTML 文件中输出,那么它会干净得多。我想如果 Javascript 来自老师控制下的外部域,这就是这样做的原因之一。
You would need quotes around it like this:
However, it would be a lot cleaner if it was just output in the HTML file. I guess if the Javascript is coming from an external domain under the teacher's control, that's one reason to do it this way.
您的引号未正确转义。尝试这样:
Your quotes are not correctly escaped. Try like this:
将链接放在单独的 HTML 文件中并将其包含在所有页面上。所有主要的网络服务器都支持这一点。例如:
Put the links in a separate HTML file and include it on all pages. All major web servers support this. For example:
<?php include('links.html'); ?>
<!--#include virtual="/links.html" -->
我建议为您维护的链接创建数组,然后可以将其放入类似的函数中:
这在服务器端代码(如 PHP)中比 Javascript 更有意义,真的,并且方法大致相同。这种风格是朝着创建一个从数据库读取项目然后使用类似功能打印出来的网站迈出的良好一步。
I'd suggest making array for the links that you maintain, and then it can be placed into a function like:
This would make more sense in server side code like PHP than Javascript, really, and the approach would be about the same. This style is a good step towards making a site that reads the items from a database and then print them out with a function like so.