该示例来自Wordpress 3.5 上 Own Plugin 中的 Display Media Uploader:
<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() {...});
但不工作...