如何将存储在JS中的变量中的URL传递给HTML文件?
我是初学者,所以我敢肯定这可能很明显。
我有一个API呼叫,该呼叫找到了我存储在一个称为senterurl的变量中的位置的当前新闻。我希望在模式中显示我的HTML文件。
这是我的模态的代码,
<div id="newsModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-heading">News</h4>
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
<div class="modal-body">
<table class="table table-striped">
<tbody>
<tr>
<td><p id="txtNews"></p></td>
</tr>
</table>
</div>
</div>
</div>
我在JS文件中尝试了以下代码,
newsUrl = result['data'][0]['url'];
newsImage = result['data'][0]['image'];
newsTitle = result['data'][0]['title'];
newsLink = ('<a href="//'+newsUrl+'" target=_blank ></a>');
$('#txtNews').html(newsLink);
没有错误。
I am a beginner so I'm sure this is probably obvious.
I have an API call which finds current news for a location which I have stored in a variable called newsUrl. I wish to show this in my HTML file within a modal.
here is the code for my modal
<div id="newsModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-heading">News</h4>
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
<div class="modal-body">
<table class="table table-striped">
<tbody>
<tr>
<td><p id="txtNews"></p></td>
</tr>
</table>
</div>
</div>
</div>
I have tried the following code within my JS file
newsUrl = result['data'][0]['url'];
newsImage = result['data'][0]['image'];
newsTitle = result['data'][0]['title'];
newsLink = ('<a href="//'+newsUrl+'" target=_blank ></a>');
$('#txtNews').html(newsLink);
No errors in the console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用:$('#txtNews').append(newsLink);
Try to use: $('#txtNews').append(newsLink);