javascript - Jquery Dialog opening multiple dialogs - Stack Overflow

I have multiple images on the same page, for each image, when clicked, I'm trying to get a dialog

I have multiple images on the same page, for each image, when clicked, I'm trying to get a dialog box to open, I have 6 of the following in my HTML set up. CUrrently when I click an image, 6 dialogs pop-up, all with the same info found in the first div. How can I modify my script to make this work properly: The HTML:

<div class="profiles">
    <a class="open" href="#">
        <img src="/../.jpg" / class="img-full"></a>
    <div class="dialog" title="Basic modal dialog">
        <p><strong>Some Text</strong></p>
        <p>
            <strong>Phone</strong>: *********<br />
            <strong>Email</strong>: <a href="mailto:[email protected]">SomeEmail</a>
        </p>
    </div>   
</div>

The JQuery:

<script type="text/javascript">
        $(".dialog").dialog({
            autoOpen: false,
            draggable: false,
            position: "center",
            width: "300px",
            modal: true,
            title: "",
            buttons: {
                "Close": function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".open")

          .click(function () {
              $(".dialog").dialog("open");
          });

    </script>

I have multiple images on the same page, for each image, when clicked, I'm trying to get a dialog box to open, I have 6 of the following in my HTML set up. CUrrently when I click an image, 6 dialogs pop-up, all with the same info found in the first div. How can I modify my script to make this work properly: The HTML:

<div class="profiles">
    <a class="open" href="#">
        <img src="/../.jpg" / class="img-full"></a>
    <div class="dialog" title="Basic modal dialog">
        <p><strong>Some Text</strong></p>
        <p>
            <strong>Phone</strong>: *********<br />
            <strong>Email</strong>: <a href="mailto:[email protected]">SomeEmail</a>
        </p>
    </div>   
</div>

The JQuery:

<script type="text/javascript">
        $(".dialog").dialog({
            autoOpen: false,
            draggable: false,
            position: "center",
            width: "300px",
            modal: true,
            title: "",
            buttons: {
                "Close": function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".open")

          .click(function () {
              $(".dialog").dialog("open");
          });

    </script>
Share Improve this question asked Sep 27, 2013 at 13:00 MarkMark 4,8738 gold badges57 silver badges93 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1

Because you have many .dialog divs. Keep only one div.

<div class="dialog" title="Basic modal dialog">
    <p><strong>Some Text</strong>

    </p>
    <p> <strong>Phone</strong>: *********
        <br /> <strong>Email</strong>: <a href="mailto:[email protected]">SomeEmail</a>

    </p>
</div>
<div class="profiles"> <a class="open" href="#">
        <img src="/../.jpg" class="img-full"></a>

</div>
<div class="profiles"> <a class="open" href="#">
        <img src="/../.jpg" class="img-full"></a>

</div>

Check this fiddle.


Update: Modify you js to this.

$(".open").click(function () {
    var div = $(this).next("div.dialog");
    var dia = $(div).dialog({
        draggable: false,
        position: "center",
        width: "300px",
        modal: true,
        title: "",
        buttons: {
            "Close": function () {
                $(this).dialog("close");
                $(this).dialog("destroy"); //need to remove the created html. otherwise the next click will not work.
            }
        }
    });
});

Dont forget to add css

.dialog {
  display:none;
}

Fiddle

Cheers!!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745533391a4631797.html

相关推荐

  • javascript - Jquery Dialog opening multiple dialogs - Stack Overflow

    I have multiple images on the same page, for each image, when clicked, I'm trying to get a dialog

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信