Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.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
Javascript 询问.html()是否具有具有特定id的img元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript 询问.html()是否具有具有特定id的img元素

Javascript 询问.html()是否具有具有特定id的img元素,javascript,jquery,html,Javascript,Jquery,Html,我想知道如何询问.html()中是否存在带有#id的图像 例如: $('#mydiv').find("iframe").contents().find("body").html(findIMGwith#id); 图像将在身体中,而不是其他地方。这可能吗?如果将参数传递到.html中,它将设置html 如果图像有一个id,你为什么不用老式的香草方式来获取它呢 document.getElementById(iframeId).contentWindow.document.getElementBy

我想知道如何询问
.html()
中是否存在带有
#id
的图像

例如:

$('#mydiv').find("iframe").contents().find("body").html(findIMGwith#id);

图像将在身体中,而不是其他地方。这可能吗?

如果将参数传递到
.html
中,它将设置html

如果图像有一个id,你为什么不用老式的香草方式来获取它呢

document.getElementById(iframeId).contentWindow.document.getElementById(imgId);

这种方法也适用于IE和旧版本。不需要jQuery。

如果将参数传递到
.html
中,它将设置html

if( $('#mydiv').find("iframe").contents().find("body #id").length > 0){
  // image#id exists
} else {
  // image#id doesn't exist
}
如果图像有一个id,你为什么不用老式的香草方式来获取它呢

document.getElementById(iframeId).contentWindow.document.getElementById(imgId);

这种方法也适用于IE和旧版本。无需jQuery。

您可以使用
document.getElementById(“id”)
获取图像。如果这是
null
undefined
,则表示图像不存在。否则,它确实存在,您可以通过
$(“img#id”).HTML()获取HTML。

您可以使用
document.getElementById(“id”)
获取图像。如果这是
null
undefined
,则表示图像不存在。否则,它确实存在,您可以通过
$(“img#id”).HTML()获取HTML

if( $('#mydiv').find("iframe").contents().find("body #id").length > 0){
  // image#id exists
} else {
  // image#id doesn't exist
}