【发布时间】:2013-01-30 05:03:26
【问题描述】:
样本来自Display Media Uploader in Own Plugin on Wordpress 3.5:
<script type="text/javascript">
var file_frame;
jQuery('.button-secondary').live('click', function( event ){
event.preventDefault();
if ( file_frame ) {
file_frame.open();
return;
}
file_frame = wp.media.frames.file_frame = wp.media(
{
title: 'Select File',
button: {
text: jQuery( this ).data( 'uploader_button_text' )
},
multiple: false
}
);
file_frame.on('select', function() {
attachment = file_frame.state().get('selection').first().toJSON();
jQuery('#IMGsrc').val(attachment.url);
});
file_frame.open();
});
问题是关于
file_frame.on('select', function() {...});
不返回动态 html。我试过这样的代码:
jQuery(document).on('select', file_frame, function() {...});
jQuery(document).on('select', file_frame.el, function() {...});
但不工作...
【问题讨论】:
-
为什么不用 .on( 而不是旧的 .live( ?
-
live 将被弃用,因为我知道...我喜欢 live((
标签: jquery wordpress media uploader wordpress-3.5