0

i have some jquery code to show iframe in modal window.

this code:

<script type="text/javascript">
      $(document).ready(function() {
            $("#modalDiv").dialog({
                modal: true,
                autoOpen: false,
                height: '800',
                width: '800',
                draggable: false,
                resizeable: false,   
                title: 'IFrame Modal Dialog'
            });
            $('#goToMyPage').click(
                function() {
                    url = '/addnews.html';
                    $("#modalDiv").dialog("open");
                    $("#modalIFrame").attr('src',url);
                    return false;
            });                 
      });
</script>

HTML:

<a id="goToMyPage" href="#">Go to My Page</a>
<div id="modalDiv">
<iframe id="modalIFrame" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" title="Dialog Title"></iframe>
</div>

i just can use for 1 link. this link:

url = '/addnews.html';

HTML:

<a id="goToMyPage" href="#">Go to My Page</a>

how i can use this code for 4-5 links?

4

2 回答 2

1

您可以在标签中的附加参数中发送 url

<a id="goToMyPage" href="#" data-url="some-url" >Go to My Page</a>

并在您的活动中使用它

$('.goToMyPage').click(
            function(e) {
                e.preventDefault();
                url = $(this).attr('data-url');
                $("#modalDiv").dialog("open");
                $("#modalIFrame").attr('src',url);
                return false;
        }); 
于 2012-09-21T10:46:58.113 回答
0

修改您的 js 以触发类而不是 ID,并修改链接以使用 href e.preventDefault() 告诉禁用链接正常打开

       $('.goToMyPage').click(
            function(e) {
                e.preventDefault();
                url = $(this).prop('href');
                $("#modalDiv").dialog("open");
                $("#modalIFrame").attr('src',url);
                return false;
        });         

然后让你的链接看起来像这样

<a class="goToMyPage" href="addnews.html">Go to My Page</a>
于 2012-09-21T10:19:54.283 回答