Jquery ui 使用jQuery UI对话框按钮的zClip on click事件
我想在jQueryUI对话框按钮中使用jQueryZclip插件,但我不知道如何适应这种情况。有人能帮我吗 提前谢谢你Jquery ui 使用jQuery UI对话框按钮的zClip on click事件,jquery-ui,jquery-plugins,zclip,Jquery Ui,Jquery Plugins,Zclip,我想在jQueryUI对话框按钮中使用jQueryZclip插件,但我不知道如何适应这种情况。有人能帮我吗 提前谢谢你 $.ajax({ url: '/music/lyrics/' + hash, success: function (data) { data = jQuery.parseJSON(data); $('#dialog-modal').html(data.lyrics);
$.ajax({
url: '/music/lyrics/' + hash,
success: function (data) {
data = jQuery.parseJSON(data);
$('#dialog-modal').html(data.lyrics);
$('#dialog:ui-dialog').dialog('destroy');
$('#dialog-modal').dialog({
modal: true,
resizable: false,
title: 'Lyric: ' + data.song,
width: 500,
height: 400,
buttons: {
'Copy' : function () {
// use zClip to copy $('#dialog-modal').text() here
}
}
});
},
error: function (msg) {
alert(msg);
}
});
我会忽略对话框按钮处理动作的正常方式,而单独使用zClip处理动作的方式。大概是这样的:
$.ajax({
url: '/music/lyrics/' + hash,
success: function (data) {
data = jQuery.parseJSON(data);
$('#dialog-modal').html(data.lyrics);
$('#dialog:ui-dialog').dialog('destroy');
$('#dialog-modal').dialog({
modal: true,
resizable: false,
title: 'Lyric: ' + data.song,
width: 500,
height: 400,
buttons: {
'Copy' : function () { return true; }
}
});
$('#dialog-modal ui-button:contains(Copy)').zclip({
path:'../whatever/ZeroClipboard.swf',
copy:$('#dialog-modal').text()
});
},
error: function (msg) {
alert(msg);
}
});
假设您使用的是jQuery 1.8+,您可以用不同的方式指定按钮来添加ID:
$("#mydialog").dialog({
...
buttons : [{
text: "Close",
click: function() {
$(this).dialog("close");
}
},{
text: "Copy to clipboard",
id: "copyButton", // here is your ID
click : function() {
alert("Sorry, copy not supported in your browser, please copy manually.");
}
}]
...
});
//after .dialog("open");
$("#copyButton").zclip({
...
clickAfter: false // dont propagate click: will suppress unsupported warning
...
});
我唯一的问题是,似乎只能在可见按钮上安装zclip,因此我在处理程序中为打开对话框的按钮调用zclip()谢谢,这非常有帮助(在我意识到我将zclip绑定到document.ready上而不是在对话框打开时)