Dynamic conversion img.src needs attention

xiaoxiao2021-03-06  65

I just wrote a thing in these two days, I need to dynamically convert img's SRC, I want to write: if (img.src == '1.jpg') img.src = '2.jpg' What does not change? Alert, I found that img.src is a path, so I cannot use img.src == '1.jpg' to judge. So how do you judge? You can use string.indexof, because img.src is included with the path string, we only look for the file name of this path to have a picture, but pay attention to the case-sensitization of the file name and then judge.

Later I changed into IF (IMG.SRC.INDEXOF ('1.jpg')! = - 1) img.src = '2.jpg' is OK.

转载请注明原文地址:https://www.9cbs.com/read-90141.html

New Post(0)