我在插件中使用此查询上载媒体文件,当我将其文件保存在wp\\u enqueue\\u script中时,除非我选择了图像,否则该代码不会返回wordpress页面。
$content .=\'<div class="col-sm-6">\';
$content .=\'<label class="fo">Upload Image</label>\';
$content .=\'<input type="button" type="button" name="txt_image"id="txt_image" class="form-control"style=" font: italic bold 12px/30px Georgia, serif;font-size:20px;" value="Upload Image">\';
$content .=\'<img src="" id="getImage" style="height:100px;width:100px;"/>\';
$content .=\'<input type="hidden" name="student_image" id="student_image"/>\';
$content .=\'</div>\';
<script>
jQuery(document).on("click","#txt_image",function(){
var image = wp.media({
title:"Upload Image",
multiple:false
}).open().on("select", function(e){
var uploaded_image = image.state().get("selection").first();
var image_data = uploaded_image.toJSON();
jQuery("#getImage").attr("src", image_data.url);
jQuery("#student_image").val(image_data.url);
});
});
</script>