简体   繁体   中英

Open JQuery Dialog Box with Multiple Buttons?

I'd like to have my Jquery dialog box open for several different buttons. I have a facebook ui feed that is called on click (i'd like to have that inside the dialog box, but that's another story). It is only opening for one button (the first button that appears in my html). Here is the code:

<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>

The buttons:

<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>

etc...

Thank you for your help!

change all id="opener" to class="opener"

and then change your js $( "#opener" ).click to $( ".opener" ).click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM