- 已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
6个月前关闭。
Improve this question
对不起,我是新的javascirpt一直试图实现的结果上的图像附件。请帮助解决方案适用。
Here is what i want to achieve
下面是我的HTML代码:
<div class="col p-5">
<div class="card" style="width: 18rem;">
<img src="./img/connecting-to-go-of-elijah.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title text-center">Connecting to God of Elijah</h5>
<p class="card-text text-center">Come and experience worship, word encounter, salvation, prayers, deliverance & prophetic declaration.</p>
<div class="row">
<div class="col-lg-12 text-center"><a href="#" class="btn btn-danger">WATCH SERMON</a></div>
<div class="col-lg-12 text-center pt-3">
<a href="#" ><img src="./img/film-solid.svg" width="10%" height="auto" class="p-1"/></a>
<a href="#" ><img src="./img/headphones-simple-solid.svg" width="10%" height="auto" class="p-1"/></a>
<a href="#" ><img src="./img/download-solid.svg" width="10%" height="auto" class="p-1"/></a>
<a href="#" ><img src="./img/book-solid.svg" width="10%" height="auto" class="p-1"/></a>
</div>
</div>
</div>
</div>
</div>
下面是我的Javascript代码
function mFeeds()
{
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
headers.append('Access-Control-Allow-Origin', 'https://mfeeder.herokuapp.com/feed');
headers.append('Access-Control-Allow-Credentials', 'true');
var requestOptions = {
method: 'GET',
redirect: 'follow',
headers: headers
};
fetch("https://mfeeder.herokuapp.com/feed", requestOptions)
.then(response => response.text())
.then(result => {
let mResults = JSON.parse(result)
for (let i = 0; i < 7; i++) {
mTitle = mResults.feeds[i].text
mDescription = mResults.feeds[i].description
mLink = mResults.feeds[i].link
console.log(mTitle, mDescription, mLink)
}
})
.catch(error => console.log('error', error));
}
如何将结果mTitle、mDescirption、mLink从JavaScript填充到HTML页面?
2条答案
按热度按时间zzwlnbp81#
实现这一点的最佳方法是在for循环中创建元素,并将它们添加到包含所有卡片的容器中。2过程如下:1-创建一个变量来保存容器; 2-获取您的数据; 3-交互并将元素发送到负责创建卡的功能; 4-将此元素附加到容器。
uqxowvwt2#