JQuery - 按 alt 或标题选择图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9074587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:17:36  来源:igfitidea点击:

JQuery - Select image by alt or title

jqueryjquery-selectorsimagealt

提问by Thomas Depole

Hello I need this JQuery to run for the image bellow it. But here's the trick I need to select the image by it's alt, I can't seem to get the JQuery to select it

你好,我需要这个 JQuery 来运行它下面的图像。但这是我需要通过 alt 选择图像的技巧,我似乎无法让 JQuery 选择它

<script>                                    
 $('img[alt="800px-Red_Bull"]').onload = function() {
 Pixastic.process(img, "desaturate", {average : false});
</script>

<img width="800" height="387" src=".../01/800px-Red_Bull.png" alt="800px-Red_Bull" title="800px-Red_Bull">

回答by Joseph Silber

Your problem is not with your selector, it's that you're not using the loadevent correctly.

您的问题不在于您的选择器,而是您没有load正确使用该事件。

Change your code to this:

将您的代码更改为:

$('img[alt="800px-Red_Bull"]').load(function() {
    Pixastic.process(img, "desaturate", {average : false});
});

回答by Sudhir Bastakoti

Try:

尝试:


$('img[alt="800px-Red_Bull"]').load(function () {
 Pixastic.process(img, "desaturate", {average : false});
});