<分区>
<分区>
我的程序(在 Dreamweaver 中运行)中有这样一行:
function go() {
if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src ))
......
......
.....
}
当我有 3 个不同的图像时,当页面中的三个图像中的任何一个彼此相等时,此函数就会运行。但是,我将如何指定哪些图像彼此相等,而不是只执行这三个中的任何一个。
例如,如果一张图像的标题为“x”,如果所有三个 test1、test2、test 的值为“x”,它将运行该函数并显示此消息,但是,它会为其他图像显示相同的消息(如果都等于'y')我想以某种方式分开消息。
最佳答案
在你的 if
语句中,你可以放置一个 switch
/case
block 来测试它是 'x', 'y ' 等。您检查哪个图像的 src
并不重要,因为您已经检查过它们都是相等的。
即
if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src ))
switch (document.test.test1.src) {
case "x":
// Do stuff
break;
case "y":
// Do other stuff
break;
}
关于javascript - 如何为特定图像源制作 If 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16625077/