Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery检查imgsrc给出未定义的_Jquery - Fatal编程技术网

jQuery检查imgsrc给出未定义的

jQuery检查imgsrc给出未定义的,jquery,Jquery,我试图检查特定的元素是否有特定的链接。所以我要这样做: 但是,它不起作用。它永远找不到它,而else只是提醒我未定义。你知道为什么吗 这是wordpress中的钩子上的钩子,但通常的jquery是有效的(以防有人想知道我为什么要尝试查找自己的链接)。元素似乎还没有加载 if($('.watchface').find('img').attr("src") == 'http://somelink.com/that/im/trying/to/find.png') {

我试图检查特定的
元素是否有特定的链接。所以我要这样做:

但是,它不起作用。它永远找不到它,而
else
只是提醒我未定义。你知道为什么吗


这是wordpress中的钩子上的钩子,但通常的jquery是有效的(以防有人想知道我为什么要尝试查找自己的链接)。

元素似乎还没有加载

if($('.watchface').find('img').attr("src") == 'http://somelink.com/that/im/trying/to/find.png')
        {
            alert("Link found");
        }
 else
 {
    alert($('.watchface').find('img').attr("src"));
 }

img元素是否具有WatchFace类它是img元素的持有者。这里的HTML:这显示了什么<代码>控制台.log($('.watchface');log($('.watchface').find('img'));console.log($('.watchface').find('img').attr('src'))它的工作部件在
.watchface
元件内是否有多个
img
?因为如果是这种情况,
find('img')
将返回jQuery集合。
 $(document).ready(
if($('.watchface').find('img').attr("src") == 'http://somelink.com/that/im/trying/to/find.png')
        {
            alert("Link found");
        }
 else
 {
    alert($('.watchface').find('img').attr("src"));
 });