Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
Html #文档内部<;对象>;关于断裂[src]_Html_Image_Onerror - Fatal编程技术网

Html #文档内部<;对象>;关于断裂[src]

Html #文档内部<;对象>;关于断裂[src],html,image,onerror,Html,Image,Onerror,我试图处理破碎的图像,以得到一个好的和干净的结果。我想要的是: 获取损坏图像图标的装备 能够定义自己的默认内容、图像或文本,并设置样式 我正在使用React,但我认为这只与HTML有关。此外,我目前正在使用Chrome,但我正在寻找一个在所有主要浏览器上都能工作的结果 我知道我可以使用img标记和onError方法: <img src="wrongUrl" onError={(e) => { e.target.src = 'https://placei

我试图处理破碎的图像,以得到一个好的和干净的结果。我想要的是:

  • 获取损坏图像图标的装备
  • 能够定义自己的默认内容、图像或文本,并设置样式
  • 我正在使用React,但我认为这只与HTML有关。此外,我目前正在使用Chrome,但我正在寻找一个在所有主要浏览器上都能工作的结果

    我知道我可以使用
    img
    标记和
    onError
    方法:

    <img
        src="wrongUrl"
        onError={(e) => {
            e.target.src = 'https://placeimg.com/200/300/animals';
        }}
    />
    
    B.在
    对象
    标记中包装默认元素:

    <object
        data="wrongUrl"
        type="image/jpg"
    >
        <img src="wrongUrl" />
    </object>
    
    这个
    #document
    元素实际上是我页面的document元素,因此它作为默认内容插入到
    对象
    标记中


    我想了解如何在此处插入
    #document
    元素,以及它与默认元素冲突的原因。

    “此#document元素实际上是我页面的document元素”-您确定它不是其他对象吗?(
    document
    ,虽然是一个DOM节点,但它不是一个元素)“为什么它与我的默认元素冲突”-什么让你认为它是冲突的?@Quentin我问这个问题,因为我不确定这个#document元素是什么,我不知道用哪个术语来表示它。我说这是«冲突»,因为它在object元素内,在默认img元素上呈现网站的副本。
    <object
        data="wrongUrl"
        type="image/jpg"
    >
        <img src="wrongUrl" />
    </object>
    
    <object data="wrongUrl" type="image/jpg">
        #document
        <!doctype html>
        <html>…</html>
        <img src="https://placeimg.com/200/300/animals">
    </object>