开发者

Preview an html page without opening it

开发者 https://www.devze.com 2022-12-26 06:07 出处:网络
On click a image how can another page bepreviewed in the same page without opening the actual page. Lets say the url /home/home.php?id=3

On click a image how can another page be previewed in the same page without opening the actual page. Lets say the url /home/home.php?id=3

The preview should be in the preview div:

 <img 开发者_StackOverflow社区src="/home/app/img/toggle.gif" onlclick="show();" />
 <div id="preview"></div>   


You can use .load() for this. Here's an example, HTML like this:

<img src="/home/app/img/toggle.gif" id="previewBtn" />
<div id="preview"></div>

jQuery like this:

$("#previewBtn").click(function() {
  $("#preview").load("/home/home.php?id=3");
});

Or, if you had lots of previews, something like this more generic works:

<a class="previewBtn" href="/home/home?id=1">Preview 1</a>
<a class="previewBtn" href="/home/home?id=2">Preview 2</a>
<div id="preview"></div>

With this jQuery:

$(".previewBtn").click(function() {
  $("#preview").load(this.href);
});


$(function() {

        $.ajax({
            url: '2.htm',
            success: function(data) {
                $('.result').html(data);
            }
        });
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消