Answers:
您可以尝试以下脚本:
var MEDIAmedia_library: function() {
var formfield = null;
var wireframe;
$('body').on('click', '#click-event-selector',function(e) {
e.preventDefault();
if (wireframe) {
wireframe.open();
return;
}
wireframe = wp.media.frames.wireframe = wp.media({
title: 'Media Library Title',
button: {
text: 'Media Library Button Title'
},
multiple: false
});
wireframe.on('select', function() {
attachment = wireframe.state().get('selection').first().toJSON();
console.log(attachment);
$('#input-field-selector').val(attachment.url);
});
wireframe.open();
});
}
#click-event-selector
您的点击事件选择器
#input-field-selector
您的输入字段值以插入选定的对象属性
您也可以将此函数包装在任何jquery模态中