简体   繁体   English

如何使用HTML从另一个页面加载图像?

[英]How do I load an image from another page using HTML?

I read that you can load an image from another page with the load method. 我读到您可以使用load方法从另一个页面加载图像。

For example: $("#result").load(url, 'tag.attribute') 例如: $("#result").load(url, 'tag.attribute')

However I need to get the path of the first image from a list on another page and put it in an <img> tag of my code to show it. 但是,我需要从另一页上的列表中获取第一张图片的路径,并将其放在代码的<img>标记中以进行显示。 I am not able to do it using jQuery (the CDN is in index.html ). 我无法使用jQuery(CDN在index.html )来做到这一点。 How can this my code below work? 我下面的代码如何工作? Can you do this with pure JavaScript to use with React? 您可以使用纯JavaScript来与React一起使用吗?

import React, {Component} from 'react'

/* global $ */

class GetImage extends Component {
state = {
    loaded: false
}
image = () => {

    const url = 'https://www.google.com/search?q=exemple&source=lnms&tbm=isch&sa=X&ved=0ahUKEwin8pXtzu3fAhXKlZAKHQ3dBAcQ_AUIDigB&biw=1536&bih=558'
    $("#content").load(url, 'div.data-ri===0.img.src')
    this.setState({loaded: true})

}
render(){
    return (
        <div>
            {this.state.loaded && <img id='content'></img>}
            <button type='button' onClick={this.image}></button>
        </div>
    )
}
}

您为什么不只是从另一个网站复制img链接,然后将其放入您网站上的img src =“”?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅使用JavaScript将表单数据从一个HTML页面传递到另一HTML页面? - How do I pass form data from one HTML page to another HTML page using ONLY javascript? 如何使用“.replaceWith”从另一个 html 页面加载数据? - How do I use '.replaceWith' to load data from another html page? 每次页面刷新时,如何将JavaScript文件中的随机图像加载到HTML中? - How do I load a random image from an array in a JavaScript file into HTML every time the page refreshes? 如何将html从当前页面附加到另一个页面? - How do I append html to another page from the current page? 如何使用 JavaScript 在 div 中加载 HTML 页面? - How do I load an HTML page in a div using JavaScript? 如何从另一个页面加载 a.php 页面并加载动态内容 - How do I load a .php page from another page and load dynamic content 如何使用javascript访问和修改HTML页面中的图像? - How do I access and modify an image in an HTML page using javascript? 如何从另一个使用jQuery load()加载的html页面执行写在主html文件中的脚本 - How to execute script written in main html file from another html page loaded using jquery load() 如何将Html页面加载到另一个页面? - how to load a Html page into another? 我如何使用相关的 jquery 函数将内容从另一个页面加载到页面中,使其工作(滑块) - how do i load content into a page from another page with the associated jquery function that makes it work (slider)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM