大家好,如果单击 img src 包含特定文本,我如何检查是否执行某些功能?
例子:
<img src="file:///C:/path/img4-dog.jpg">,
<img src="file:///C:/path/img4-cat.jpg">
如果单击的 img src 包含“dog”之类的东西,则运行警报?
最佳答案
$('img').click(function(){
if (this.src.indexOf("dog") != -1)
alert('contains dog');
})
关于javascript - 如果单击 img src 包含特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12415318/