如何获得img src值 [英] how to get img src value

查看:142
本文介绍了如何获得img src值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在div标签中有一些内容...

I have some contents inside div tag...

在该div标签内容内,我必须搜索img src标签值

within that div tag content I have to search for img src tag value

基于该值,我必须突出显示一些图像并显示一些div内容

based on that value i have to highlight some images and to show some div content

例如

如果img src值包含" http://google.com/test/test.img"必须突出显示并显示img突出显示div内容

if img src value contains "http://google.com/test/test.img" have to highlight and to show img is highlighted div content

如果img src值包含某些特定路径"news/images/test1.jpg",则必须突出显示并显示img突出显示div内容

if img src value contains some specific path "news/images/test1.jpg" have to highlight and to show img is highlighted div content

如果img src值包含一些特定路径"news/articles/images/test1.gif",则无需突出显示,并且显示img未突出显示div内容.

if img src value contains some specific path "news/articles/images/test1.gif" no need to highlight and to show img is not highlighted div content.

推荐答案

我认为您的意思是,有两种情况需要突出显示图像:

I think you mean that there are two possible scenarios where you want to highlight the image:

var $img = $("#someImage");
var src = $img.attr("src");
if(src == 'http://google.com/test/test.img' || src == 'news/images/test1.jpg') {
    $img.addClass("highlight");
    // or
    $img.css("border", "3px solid yellow");
}

根据您的评论进行

$("#formpreview img[src*=google.com]").addClass("highlight");

这篇关于如何获得img src值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆