首先,我知道有很多问题与这个问题有关。但问题是,它们都与jquery有某种关联。
但我的问题实现了普通javascript。
基本上,除了onselect()之外,其他一切都正常工作。我无法获取附件的URL。
Here is the code.
var custom_uploader;
var uploadButton = document.getElementById(\'upload_logo_button\');
uploadButton.addEventListener("click", function(e) {
e.preventDefault();
if ( custom_uploader ) {
custom_uploader.open();
return;
}
custom_uploader = wp.media.frames.file_frame = wp.media({
frame: \'select\',
title: \'Choose Image\',
button: {
text: \'Select Image\'
},
multiple: false
});
custom_uploader.onselect = function() {
var attachment = custom_uploader.state().get(\'selection\').first().toJSON();
console.log(attachment);
var uploadLogoImage = document.getElementById("upload_image").innerHTML(attachment.url);
}
//Open the uploader dialog
custom_uploader.open();
});
请有人告诉我为什么我无法获得图像的URL,即使图像成功上传到WP媒体。提前谢谢。如果有人需要更多信息,请随时询问。再次感谢。