开发者

creating popup content with jquery

开发者 https://www.devze.com 2023-01-05 04:48 出处:网络
Let\'s say i have this code <p id=\"test\"> some content <p> <a href=\"#\" id=\"test-link\">Open</a>

Let's say i have this code

<p id="test">
  some content
<p>
<a href="#" id="test-link">Open</a>

Now i want -using javascript/jquery- to create a popup window, the window content is the content of test paragraph, when test-link is clicked. How cou开发者_开发技巧ld this be done?


  <a href="javascript:popup();"  id="test-link">Open</a>

function popup()
{
  var generator=window.open('','name','height=400,width=500');

  generator.document.write('<html><head><title>Popup</title>');
  generator.document.write($("#test").html());
  generator.document.write('</body></html>');
  generator.document.close();
}


You can do this using jQuery UI (dialog) (see examples in the reference documentation).


im using http://defunkt.github.com/facebox/ its nice.


Use jQuery UI dialog to show popup.

For your html:

$(function()
{
    $("#test-link").click(function()
    {
         $("#test").dialog({ resizable: true,
                modal: false, draggable: true
         });
    });
});

If you don't want to go for jQuery UI dialog then you can use ThickBox.

0

精彩评论

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