我对 Javascript 以及基本上与网络相关的所有内容都很陌生
编码。我在 FF 中使用 InnerHTML 有一个简单的问题,我希望你能
帮助我。
我正在使用这段代码,它应该生成一个简单的 html 输入行,
在 IE 中它工作正常(尽管当我加载它时我得到“我应该吗?
启用顶部的 activeX msg),但在 FF 中它根本不起作用,我可以
通过源代码在页面上看到它,但它没有显示任何内容...
;
<脚本类型=“text/javascript”>
var siteBoxes = '
VALUE="'+arr1[i]+'"/> '+arrNames[i]+'
';
}
站点框 += '';
document.getElementById("mainDiv").innerHTML=siteBoxes;
我确信这是一个简单的解决方案,我尝试在网上搜索,但是
我已经没有力气了,我希望你们中的任何一个好心人
可以帮助我。
提前致谢!!!
好吧,问题出在头部的数组定义上。
我刚刚注意到,在 FF 的错误控制台中,我收到一条消息,指出 arr1 未定义,但确实如此,我什至尝试将其移动到正文,但它没有改变,仍然未定义......并且它在 IE 中工作。
可能与数组定义有关?和IE、FF有区别吗???
var arr1 = new Array(
"http://www.google.com",
"http://www.yahoo.com",
"http://www.cnet.com",
"http://www.google.ar/search?q="
);
再说一次,它在 IE 中运行良好,但在 FF 中则不然
i'm pretty new to Javascript and basiclly everything related to web
coding. i have a simple problem using InnerHTML in FF, i hope you can
help me.
i'm using this code, that should generate a simple html input line,
and in IE it works fine (although when i load it i get the "should i
enable activeX msg on top), but in FF it doesn't work at all, i can
see it's on the page thorugh source, but it doesn't show anything...
<div id="mainDiv"></div>
<script type="text/javascript">
var siteBoxes = '<form action=HTMLPage.htm name="myform">';
for (var i = 0; i < arr1.length; i++) {
siteBoxes += '<INPUT TYPE="checkbox" id="box'+i+'"
VALUE="'+arr1[i]+'"/> '+arrNames[i]+'
';
}
siteBoxes += '';
document.getElementById("mainDiv").innerHTML=siteBoxes;
i'm sure it's a simple solution, and i tried searching on the web, but
i'm running out of strength for that, i hope any of you kind people
can help me.
thanks in advance!!!
ok, the problem is with the array definition in the head.
i just noticed that in the error console in FF i get a msg that the arr1 is undefined, but it is, i even tried moving it to the body and it doesn't change, still undefined... and it works in IE.
could it be something with the array definition? is it different from IE and FF???
var arr1 = new Array(
"http://www.google.com",
"http://www.yahoo.com",
"http://www.cnet.com",
"http://www.google.ar/search?q="
);
again, it works great in IE, but not in FF
发布评论
评论(5)
我第一眼就注意到了一些事情。
至少从您向我们提供的代码中从未声明过 arr1 。
Somethings I noticed at first glance.
arr1 is never declared at least from the code you present to us.
对我来说适用于 Opera、IE 和 FF。
尝试取消转义输出;
Works in Opera, IE and FF for me.
Try unescaping the output;
脚本标记中的结束引号有问题。如果我删除它并输入一个新的,代码就可以工作。
There is something wrong with the ending quotation mark in your script tag. If I delete it and type a new one, the code works.
你的其余代码一定有问题,因为当我更改它时。效果很好。
There must be a problem with the rest of your code because when I change it. It works fine.
这也许是一种更简洁的实现方法(也请参阅代码中的注释):
建议这样做的主要原因是字符串连接可能非常慢,尤其是当您有很多长字符串时。在 Firefox 中这不是一个大问题,但在 IE 中这绝对是一个问题。因此,将字符串推入数组,然后在最后将它们连接起来会给你带来更好的性能。
Here's perhaps a cleaner way of implementing this (see comments in code as well):
The primary reason for suggesting this is that string concatenation can be very slow, especially if you have lots of long strings. It's not as big an issue in Firefox, but it's definitely an issue in IE. So pushing strings onto an array, then joining them at the end will give you better performance.