0
我想让我的jquery对话框打开几个不同的按钮。我有一个叫做点击的facebook ui feed(我想在对话框中有这个,但这是另一个故事)。它只开放一个按钮(第一个按钮出现在我的HTML)。下面是代码:打开多个按钮的JQuery对话框?
<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>
等等
谢谢您的帮助!
这是无效的有与HTML相同ID的多个元素。我猜jQuery使用'document.getElementById()'来匹配'#opener',它只返回其中的一个。改为使用'class ='opener''和'$('。opener')'。 – millimoose 2013-02-22 21:42:22
当我用$('。opener')代替$(“#opener”)时,它们都没有打开 – user1072337 2013-02-22 22:05:06
nm,这个工作,谢谢! – user1072337 2013-02-22 22:19:41