如何为特定图像源制作 If 语句?

编程入门 行业动态 更新时间:2024-10-25 15:22:58
本文介绍了如何为特定图像源制作 If 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的程序中有这一行(在 Dreamweaver 中运行),如下所示:

I have this line in my program (Run in Dreamweaver) which is the following:

function go() { if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src )) ...... ...... ..... }

当我有 3 个不同的图像时运行此函数,当页面中的三个图像彼此相等时.但是,我将如何指定哪些图像彼此相等,而不是仅执行三项中的任何一项.

This function runs when I have 3 different images which when either of the three equal each other in the page. However, how would I make it to specify which images to equal each other, instead of just doing any of the three.

例如,如果一张图片的标题为x",如果所有三个 test1、test2、test 的值都为x",它将运行该函数并显示此消息,但是,它会为其他图像显示相同的消息(如果都相等 'y') 我想以某种方式有单独的消息.

For ex, if one image is titled 'x' if all three test1,test2,test are of value 'x' it will run the function and display this message, however, it displays the same message for the other images (If all equal 'y') Id like to have separate messages somehow.

推荐答案

我会将比较与单独的函数分开,以当前图像元素为参数,并使用此方法处理不同的图像对象:

I'd separate the comparison to a separate function with current image element as parameter and use this method with different image objects:

function compare(imgElem){ if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src )) console.log(imgElem.id,"triggered"); // or something else } } compare(document.test.test1); compare(document.test.test2); compare(document.test.test3);

但是根据您要比较的元素数量,解决方案可能不准确.对于大量元素,请尝试使用地图.

However the solution might not be accurate depending on how many elements you're comparing. For large number of elements, try using a map.

更多推荐

如何为特定图像源制作 If 语句?

本文发布于:2023-08-07 19:47:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321412.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   语句   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!