I have a small chunk of code I can't seem to get working.
(我有一小部分代码似乎无法正常工作。)
I am building a website and using JavaScript for the first time.(我正在建立一个网站并首次使用JavaScript。)
I have my JavaScript code in an external file 'Marq_Msg.js' which looks like this:(我在外部文件'Marq_Msg.js'中有我的JavaScript代码,如下所示:)
var Messages = new Array();
Messages[0] = "This is message 1";
Messages[1] = "This is message 2";
Messages[2] = "This is message 3";
Messages[3] = "This is message 4";
function scroll_messages()
{
for (var i = 0; i < Messages.length; i++)
document.write(Message[i]);
}
and in my HTML file 'Index.html' I am trying to call it like this:
(在我的HTML文件'Index.html'中我试图这样称呼它:)
<div id="logo">
<marquee scrollamount="5" direction="left" loop="true" height="100%" width="100%">
<strong><font color="white"><script src="Marq_Msg.js">scroll_messages()</script></font></strong>
</marquee>
</div>
The 'logo' div is a CSS piece that I'm trying to marquee inside of.
('logo'div是一个我试图在其中进行选择的CSS片段。)
If I put the code embedded inside the 'head' tag and call it, it works perfectly!(如果我把代码嵌入'head'标签内并调用它,它就能完美运行!)
There are a few other things id like to do with this code (like space the messages out a little) but I can't get the code to work in the first place.(还有一些与此代码有关的其他事情(比如将消息空间分开一点)但我无法让代码首先工作。)
I've also tried adding:(我也尝试过添加:)
<script src="Marq_Msg.js"></script>
in the 'head' tag with a separate call, that was a no go.
(在'head'标签中单独调用,这是不行的。)
I also tried instead using:(我也尝试使用:)
<script type="text/javascript" src="Marq_Msg.js">scroll_messages()</script>
Hell, i even had the function try returning a string (even hardcoded a simple "hello" to be returned) but that didnt work either with and without the 'type':
(地狱,我甚至有函数尝试返回一个字符串(甚至硬编码一个简单的“你好”要返回)但是,无论有没有'类型':)
//Marq_Msg.js
function scroll_messages()
{
return "hello";
}
//index.html
<script type="text/javascript" src="Marq_Msg.js">document.write(scroll_messages())</script>
What am I missing?
(我错过了什么?)
Any help would be greatly appreciated!!(任何帮助将不胜感激!!)
I've looked all over Google, and every site I find wants to do it using some 'form'.(我看了整整一遍谷歌,我找到的每个网站都想用一些'形式'来做。)
I just want messages to be displayed across, no form attached.(我只是想要显示消息,没有附加表单。)
ask by Kevin Fauver translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…