[英]How can I show only one div id from an external html file inside a popup modal?
I have some content on an external html file that I am displaying in a popup modal using jQuery Modal . 我在使用jQuery Modal的弹出模式中显示的外部html文件上有一些内容。 I am able to display the whole page fine, but I would like to only show one div at a time depending on which link is clicked. 我可以很好地显示整个页面,但是我只想一次显示一个div,具体取决于单击哪个链接。
The content on the external page looks like this: 外部页面上的内容如下所示:
<div class="review" id="one">This is review #1</div>
<div class="review" id="two">This is review #2</div>
<div class="review" id="three">This is review #3</div>
The links on the main page are coded like: 主页上的链接编码如下:
<a class="link" href="external.html" data-target="#two" rel="modal:open">Read review</a>
Then I have some Javascript that I thought would allow it to only show the selected div id depending on which link is clicked: 然后我有一些Javascript,我认为该Javascript仅会根据单击的链接显示所选的div ID:
$(document).ready(function() {
$('.link').on('click', function() {
var target = $(this).data('target');
$('.review').not(target).hide();
$(target).show();
});
});
This shows all the content from the external html and not just one selected div. 这显示了来自外部html的所有内容,而不仅仅是一个选定的div。
Is there a way to show only one div id from an external html loaded into a modal? 有没有一种方法可以显示从外部HTML加载到模式中的一个div ID?
Update: I have attempted to implement Bhojendra's solution below, but am now getting the error: 更新:我试图在下面实现Bhojendra的解决方案,但是现在出现错误:
"TypeError: null is not an object (evaluating 'this.$blocker.fadeOut')"
The link to view the code: https://drive.google.com/open?id=1n61Buty8oexE369jdxCi4lZ9M9wj2SaP 查看代码的链接: https : //drive.google.com/open?id=1n61Buty8oexE369jdxCi4lZ9M9wj2SaP
From the documentation example that you linked, you can do like: 从您链接的文档示例中,您可以执行以下操作:
$('.link').click(function(event) {
event.preventDefault();
target = $(this).data('target');
$.get(this.href, function(html) {
$(html).find(target).appendTo('body').modal();
});
});
A better to have modal content wrapper in your body: 体内最好有模式内容包装器:
<div id="modal-content"></div>
Now, in jQuery, use this: 现在,在jQuery中,使用以下命令:
$('#modal-content').html($(content).find(target)).modal()
// html parameter renamed ^^ to content
I meant to use: 我打算使用:
$('.link').click(function(event) {
event.preventDefault();
target = $(this).data('target');
$.get(this.href, function(content) {
$('#modal-content').html($(content).find(target)).modal()
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.