Safari和JavaScript数组 [英] Safari and JavaScript arrays

查看:113
本文介绍了Safari和JavaScript数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在查询JavaScript社区,了解是否其他人在使用Safari [1]和JavaScript时遇到问题

数组:


myImages = [

" images / image0.jpg",

" images / image1 .jpg",

" images / image2.jpg",

];


然后像这样引用:


document.images [1] .src = myImages [1];


这是Safari的已知错误吗?破碎的阵列?


(BTW以上适用于所有主流浏览器的

最新版本;我试过的那些)

>
我可以在src属性中写一个字符串文字:

document.images [1] .src =" images / image1.jpg" ;;


并实现图像替换,但不能从数组中引用字符串

literal。


是什么给出的?我在做什么真的很蠢(TM)?


提前感谢您的建议。


干杯,

DK


[1]参考Safari版本1.0.1

Hello,

I am querying the JavaScript community to learn if
others are having problems with Safari[1] and JavaScript
arrays:

myImages = [
"images/image0.jpg",
"images/image1.jpg",
"images/image2.jpg",
];

then referenced like this:

document.images[1].src = myImages[1];

Is this a known bug with Safari? Broken arrays?

(BTW the above works in every major browser''s
recent version; those I have tried)

I can write a string literal into the src property:

document.images[1].src = "images/image1.jpg";

and achieve image replacement, but not when the string
literal is referenced from an array.

What gives? Am I doing something Really Stupid (TM)?

Thanks in advance for advice.

Cheers,
DK

[1] Referring to Safari version 1.0.1

推荐答案

>我正在查询JavaScript社区,了解
> I am querying the JavaScript community to learn if
其他人是否遇到Safari [1]和JavaScript
数组:

myImages = [
; images / image0.jpg",
" images / image1.jpg",
" images / image2.jpg",
];


嗯。那里有换行符。在一条线上试一试。


我可以告诉它几乎可以告诉Safari处理数组与othres相同。至少我没有看到问题。


杰夫

然后像这样引用:

document.images [1] .src = myImages [1];

这是Safari的已知错误吗?破碎的阵列?

(顺便说一句,以上版本适用于所有主流浏览器的最新版本;我试过的那些)

我可以写一个字符串文字到src属性:

document.images [1] .src =" images / image1.jpg" ;;

实现图像替换,但不是当字符串
literal是从数组中引用的。

是什么给出的?我在做什么真的很蠢(TM)?

提前感谢您的建议。

干杯,
DK

[1]参考Safari版本1.0.1
others are having problems with Safari[1] and JavaScript
arrays:

myImages = [
"images/image0.jpg",
"images/image1.jpg",
"images/image2.jpg",
];
Hmmm. There''s line breaks in there. Try it on one line.

Near as I can tell tell Safari handles arrays the same as othres. At least I
haven''t seen problems.

Jeff


then referenced like this:

document.images[1].src = myImages[1];

Is this a known bug with Safari? Broken arrays?

(BTW the above works in every major browser''s
recent version; those I have tried)

I can write a string literal into the src property:

document.images[1].src = "images/image1.jpg";

and achieve image replacement, but not when the string
literal is referenced from an array.

What gives? Am I doing something Really Stupid (TM)?

Thanks in advance for advice.

Cheers,
DK

[1] Referring to Safari version 1.0.1



这是一个奇怪的...


这里是底线:


注意不要在变量命名空间中使用相同的名称,并且在Safari版本< = 1.2上使用
选择器命名空间。 1(125.1)。


我做的是这样的事情:


document.getElementById(" myImage")。s​​rc = myImage [索引];


我有一个标有myImage的字符串数组。并且

和HTML中的id选择器名为myImage。


当修改JavaScript数组名称以便它将

没有与id选择器冲突,Safari工作正常。


所以,我修复它的方法只是改变我的阵列名称

to ; myImages"数组。


欢呼,

DK
This was a weird one...

Here''s the bottom line:

Be careful to not use the same names in varible namespace and
selector namespace on Safari version <= 1.2.1 (125.1).

I was doing something like this:

document.getElementById("myImage").src = myImage[index];

where I had an array of strings labelled "myImage" and
and id selector in the HTML called "myImage".

When the JavaScript array name was modifed so that it would
not clash with the id selector, Safari worked properly.

So, my way of fixing it was simply to the change my array name
to "myImages" array.

Cheers,
DK


Duderonomoy< Se *@reply.to>在消息新闻中写道:< pa **************************** @ reply.to> ...
Duderonomoy <Se*@reply.to> wrote in message news:<pa****************************@reply.to>...
其中我有一个标有myImage的字符串数组。在HTML中称为myImage的
和id选择器。

当JavaScript数组名称被修改以便它不会与id选择器冲突时,Safari正常工作。
where I had an array of strings labelled "myImage" and
and id selector in the HTML called "myImage".

When the JavaScript array name was modifed so that it would
not clash with the id selector, Safari worked properly.




它是否与IE具有相同的行为。你可以通过id属性值在javascript中引用一个页面

元素吗?例如,如果你




[xml id =" xmlData"] [/ xml]


在javascript中你可以像这样引用它:


xmlData.src =''/ xml / datata'';


如果所以这将是冲突的原因。



Does it have the same behaviour as IE then. You can refer to a page
element in javascript by its id attribute value? For example if you
have

[xml id="xmlData"][/xml]

In javascript you can refer to it like this:

xmlData.src = ''/xml/data.xml'';

If so that''d be the cause of the clash.


这篇关于Safari和JavaScript数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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