Javascript,在IE中运行良好,但在Firefox Mozilla中它会产生问题 [英] Javascript, works good in IE but in Firefox Mozilla it gives problems

查看:50
本文介绍了Javascript,在IE中运行良好,但在Firefox Mozilla中它会产生问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个在IE浏览器中运行的脚本很棒,但是在firefox中它有问题。

我明白有一些对象在IE和Mozilla中以不同方式访问

。任何人都可以让我知道我需要在

文件中进行更改以制作一个可以在Firefox上正常运行的副本吗?


这是指向文件:
http://people.emich.edu/ srehman2 / study / polls.html 点击右上角显示的''构建

酒吧''链接。我也在这里复制源代码

代码,


===================== ============================= =======

< script language =" ; javascript">

函数BuildResults()

{

var str;

var imageWidths = new Array ();

var imageName = new Array();

var labelName = new Array();

var imageSize = 140;

var BarImage =" images / poll_yellow.gif";

var t = new Array();

var color = new Array();

t [0] = 60;

t [1] = 30;

t [2] = 50;

t [3] = 112;


color [0] =''red'';

color [1] ='''blue'';

color [2] =''silver'';

color [3] =''green'';


str = str +''< table cellspacing = 2 cellpadding = 0 border = 0>< tr>< td>'';

for(var i = 0; i< t.length; i ++ )

{

imageWidths [i] = Math.r ound(imageSize *(Math.round(t [i])/ 100));

imageName [i] =" imageResult" + i;

labelName [i] =" spanPercentage" + i;

str = str +''< table cellspacing = 2 cellpadding = 0 border = 0 height = 4>'';

str = str +'' < tr>< td bgcolor =''+ color [i] +''>< img name =''+

imageName [i] +''id =''+ imageName [i] +''src =" images / pixel.gif" width = 1

height = 1 border = 0>< / td>< td>< span id =''+ labelName [i] +''>''+

Math.round(t [i])+''%< / span>< / td>< / tr>'';

str = str +'' < / table>'';


}

str = str +"< / td>< / tr>< / table> " ;;

document.getElementById(''divText'')。innerHTML = str;

for(var x = 0; x< imageWidths.length; x ++)

{

var name =" imageResult" + x;

var image = document.getElementById(imageName [x]);


setTimeout(" Wait()",10);

if(image!= null)

{

for(var i = 0; i< = imageWidths [x]; i ++)

{

string =" IncreaseSize(" + i +",''" + imageName [x] +"'',''" +

labelName [x] +"'',''" + imageSize +"'')" ;;

setTimeout(string,40 * i);

}

}

}

}

函数Wait()

{

//等一下

}


函数IncreaseSize(Size,ImageName,LabelName ,ImageSize)

{

var image = document.getElementById(ImageName);

var label = document.getElementById(LabelName);


if(image!= null)

{

image.width =尺寸;

图片。 height = 1;

label.innerHTML = Math.round((Size / ImageSize)* 100)+"%&quo t ;;

}

}

< / script>

< span style =" cursor :指针; text-decoration:下划线

onclick =" BuildResults()">

构建吧

< / span>


< span name =" divText" id =" divText">< / span>

============================= ===================== =======


它在IE中显示栏,但在Firefox中它显示没有显示任何东西。


提前致谢。


-Shafiq。

Hello everyone,

I have a script that runs in IE great, but in firefox it has problems.
I understand that there are some objects that are accessed differently
in IE and Mozilla. Can anybody let me know what I need to change in the
file to make a copy that would run fine on Firefox?

Here is the link to the file:
http://people.emich.edu/srehman2/study/polls.html click on the ''Build
Bars'' link displayed at the top-right corner. I am copying the source
code here also,

================================================== =======
<script language="javascript">
function BuildResults()
{
var str;
var imageWidths = new Array();
var imageName = new Array();
var labelName = new Array();
var imageSize = 140;
var BarImage = "images/poll_yellow.gif";
var t = new Array();
var color = new Array();
t[0] = 60;
t[1] = 30;
t[2] = 50;
t[3] = 112;

color[0] = ''red'';
color[1] = ''blue'';
color[2] = ''silver'';
color[3] = ''green'';

str = str + ''<table cellspacing=2 cellpadding=0 border=0><tr><td>'';
for(var i=0;i<t.length;i++)
{
imageWidths[i] = Math.round(imageSize * (Math.round(t[i])/100));
imageName[i] = "imageResult" + i;
labelName[i] = "spanPercentage" + i;
str = str + ''<table cellspacing=2 cellpadding=0 border=0 height=4>'';
str = str + ''<tr><td bgcolor='' + color[i] + ''><img name='' +
imageName[i] + '' id='' + imageName[i] + ''src="images/pixel.gif" width=1
height=1 border=0></td><td><span id='' + labelName[i] + ''>'' +
Math.round(t[i]) + ''%</span></td></tr>'';
str = str + ''</table>'';

}
str = str + "</td></tr></table>";
document.getElementById(''divText'').innerHTML = str;
for(var x = 0; x< imageWidths.length; x++)
{
var name = "imageResult" + x;
var image = document.getElementById(imageName[x]);

setTimeout("Wait()", 10);
if(image != null)
{
for(var i = 0; i <= imageWidths[x]; i++)
{
string = "IncreaseSize("+i+", ''"+imageName[x]+"'', ''" +
labelName[x]+"'', ''" + imageSize + "'')";
setTimeout(string, 40 * i);
}
}
}
}
function Wait()
{
//Wait for a second
}

function IncreaseSize(Size, ImageName, LabelName, ImageSize)
{
var image = document.getElementById(ImageName);
var label = document.getElementById(LabelName);

if(image != null)
{
image.width = Size;
image.height = 1;
label.innerHTML = Math.round((Size/ImageSize) * 100) + "%";
}
}
</script>
<span style="cursor: pointer; text-decoration: underline"
onclick="BuildResults()">
Build bars
</span>

<span name="divText" id="divText"></span>
================================================== =======

It displays bars in IE but in firefox it do not display anything.

Thanks in advance.

-Shafiq.

推荐答案

sh*******@gmail.com 在04上说/ 04/2006 7:07 AM AEST:
sh*******@gmail.com said on 04/04/2006 7:07 AM AEST:
大家好,

我有一个在IE浏览器中运行的脚本很棒,但是在firefox中它有问题。
我知道在IE和Mozilla中有一些对象可以被不同地访问。任何人都可以让我知道我需要在
文件中更改什么来制作一个可以在Firefox上正常运行的副本吗?

以下是该文件的链接:
http://people.emich.edu/srehman2/study/polls.html 点击右上角显示的Build
Bars链接。我也在这里复制源代码

============================= ===================== =======
< script language =" javascript">


不推荐使用language属性,类型是必需的:


< script type =" text / javascript">


函数BuildResults()
{
var str;
var imageWidths = new Array();


发布代码时,请使用空格进行缩进而不是标签,每个级别使用2

或4个空格。


您可以使用以下内容初始化数组:


var imageWidths = [];


var imageName = new Array();
var labelName = new Array();
var imageSize = 140;
var BarImage =" images / poll_yellow.gif";
var t = new Array();
var color = new Array();
t [0] = 60;
t [1] = 30;
t [2] = 50;
t [3] = 112;


您可以将此数组初始化为:


var t = [60,30,50,112];

color [0] =''red'';
color [1] ='''blue'';
color [2] ='''silver'';
color [3 ] =''绿色'';


这一个:


var color [''red'',''blue'',''silver'',' 'green''];


str = str +''< table cellspacing = 2 cellpadding = 0 border = 0>< tr>< td>'';
for(var i = 0; i< t.length; i ++)
{
imageWidths [i] = Math.round(imageSize *(Math.round(t [i])/ 100) );
imageName [i] =" imageResult" + i;
labelName [i] =" spanPercentage" + i;
str = str +''< table cellspacing = 2 cellpadding = 0 border = 0 height = 4>'';
str = str +''< tr>< td bgcolor =''+ color [i] +''>< img name =''+
imageName [i] +''id =''+ imageName [i] +'src =" images / pixel.gif" width = 1
---------------------- ^^ ----------------- ^^ ^


您没有引用id属性的值,并且在值的结尾和名称的开头之间没有

空格

src属性,所以HTML看起来像:


... id =''imageResult0src =" images / pixel.gif"''.. 。


引用属性总是一个好主意,即使不是严格必要的b $ b。在src属性之前插入空格可以解决问题

现在...


如果使用严格的doctype,Firefox将显示更改的百分比

但不是增长的酒吧。将它带入quirksmode(删除任何参考

到doctype),你会看到与IE相同的结果。


在CSS论坛中调查这些问题:


news:comp.infosystems。 www.authoring.stylesheets


顺便提一下,使用

div为条形图并简单地修改它们的样式属性可以实现更高效的结果,有

绝对不需要每次都生成大量的嵌套表。


height = 1 border = 0>< / td>< td>< ; span id =''+ labelName [i] +''>''+
Math.round(t [i])+''%< / span>< / td>< / tr> ; '';


不允许发布的代码自动换行,手动将其换成约70

个字符,以便进行一些回复。

[...] setTimeout(" Wait()",10);
[...]

功能等待()
//
//等一下
}
Hello everyone,

I have a script that runs in IE great, but in firefox it has problems.
I understand that there are some objects that are accessed differently
in IE and Mozilla. Can anybody let me know what I need to change in the
file to make a copy that would run fine on Firefox?

Here is the link to the file:
http://people.emich.edu/srehman2/study/polls.html click on the ''Build
Bars'' link displayed at the top-right corner. I am copying the source
code here also,

================================================== =======
<script language="javascript">
The language attribute is deprecated, type is required:

<script type="text/javascript">

function BuildResults()
{
var str;
var imageWidths = new Array();
When posting code, use spaces for indentation rather than tabs, with 2
or 4 spaces per level.

You can initialise an array with:

var imageWidths = [];

var imageName = new Array();
var labelName = new Array();
var imageSize = 140;
var BarImage = "images/poll_yellow.gif";
var t = new Array();
var color = new Array();
t[0] = 60;
t[1] = 30;
t[2] = 50;
t[3] = 112;
You can initialise this array as:

var t = [60, 30, 50, 112];

color[0] = ''red'';
color[1] = ''blue'';
color[2] = ''silver'';
color[3] = ''green'';
And this one:

var color[''red'', ''blue'', ''silver'', ''green''];

str = str + ''<table cellspacing=2 cellpadding=0 border=0><tr><td>'';
for(var i=0;i<t.length;i++)
{
imageWidths[i] = Math.round(imageSize * (Math.round(t[i])/100));
imageName[i] = "imageResult" + i;
labelName[i] = "spanPercentage" + i;
str = str + ''<table cellspacing=2 cellpadding=0 border=0 height=4>'';
str = str + ''<tr><td bgcolor='' + color[i] + ''><img name='' +
imageName[i] + '' id='' + imageName[i] + ''src="images/pixel.gif" width=1 ----------------------^^-----------------^^^

You have not quoted the value of the id attribute and there is no
whitespace bewteen the end of the value and the start of the name of the
src attribute, so the HTML looks like:

... id=''imageResult0src="images/pixel.gif"'' ...

It is always a good idea to quote attributes even when not strictly
necessary. Inserting a space before the src attribute fixes the problem
for now...

If you use a strict doctype, Firefox will show the changing percentages
but not the growing bars. Trip it into quirksmode (remove any reference
to doctype) and you''ll see the same results as IE.

Investigate these issues in a CSS forum:

news:comp.infosystems.www.authoring.stylesheets

Incidentally, a much more efficient result could be achieved by using
divs for the bars and simply modifying their style attributes, there is
absolutely no need to generate a mass of nested tables every single time.

height=1 border=0></td><td><span id='' + labelName[i] + ''>'' +
Math.round(t[i]) + ''%</span></td></tr>'';
Don''t allow posted code to auto-wrap, manually wrap it at about 70
characters to allow for a few replies.
[...] setTimeout("Wait()", 10); [...]
function Wait()
{
//Wait for a second
}




你打算怎么做?

[...]

-

Rob

团体常见问题解答:< URL:http://www.jibbering.com/FAQ>



How do you intend to do that?
[...]
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>


IE 5+是95%的付费用户使用。谁在乎什么

FireFox,Netscape或Opera呢。去获胜者!

IE 5+ is what 95 per cent of paying cutomers use. Who cares what
FireFox, Netscape or Opera does. Go for the winner!


el ** *******@electrician.com 写道:
IE 5+是95%的付费用户使用的。谁在乎FireFox,Netscape或Opera的作用。去赢家!
IE 5+ is what 95 per cent of paying cutomers use. Who cares what
FireFox, Netscape or Opera does. Go for the winner!



你回复什么,或者只是拖钓?


-

伊恩柯林斯。


Are you replying to something, or simply trolling?

--
Ian Collins.


这篇关于Javascript,在IE中运行良好,但在Firefox Mozilla中它会产生问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆