用多个按钮打开JQuery对话框?

时间:2013-02-22 21:39:51

标签: javascript jquery facebook

我希望为几个不同的按钮打开我的Jquery对话框。我有一个在点击时调用的facebook ui feed(我希望在对话框中有这个,但这是另一个故事)。它只打开一个按钮(我的html中出现的第一个按钮)。这是代码:

<script>
$(function() {
  $( "#dialog-modal" ).dialog({autoOpen: false, resizable: false, draggable: false, height: 250, width: 500, modal: true, dialogCLass: 'main-dialog-class'});

  $( "#opener" ).click(function() {
                       $( "#dialog-modal" ).dialog( "open" );

                       $.getJSON(
                                 "/like_artist.php", // The server URL
                                 { artist_id : $(this).data('artist_id') }, // Data you want to pass to the server.
                                 function(json) {

                                 var artist = json[1];

                                    var text = '';
                                    text = ' ' +  artist ;


                                    FB.ui({
                                    method: 'feed',
                                   // redirect_uri: '/index.php',
                                    link: 'WEBPAGE',
                                    name: '',
                                    caption: '',
                                    description: ''

                                    });


                                    $('#dialog-modal').text(text);

                                    alert(artist);
                                 }// The function to call on completion.
                                 );

        });

  });

</script>

按钮:

<button type="button" id="opener" data-artist_id="3">Play My City</button>

<button type="button" id="opener" data-artist_id="4">Play My City</button>

<button type="button" id="opener" data-artist_id="2">Play My City</button>

等...

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

将所有id="opener"更改为class="opener"

然后将您的js $( "#opener" ).click更改为$( ".opener" ).click