[英]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.