我找不到代码有什么问题,所以我使用了在互联网上找到的另一个代码,现在窗口打开了。
var file_frame;
$(\'#csv_file_button\').on(\'click\', function(event){
event.preventDefault();
if ( file_frame ) {
file_frame.open();
return;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: $( this ).data( \'File upload\' ),
button: {
text: $( this ).data( \'Upload\' ),
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( \'select\', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get(\'selection\').first().toJSON();
$(\'#csv_file\').attr(\'value\',attachment.url);
});
// Finally, open the modal
file_frame.open();
});