WordPress媒体Uploader jQuery多按钮只得到一个值(得到相同的值给所有按钮),我不知道如何获得使用多个按钮的确切值?我犯了什么错误?
我的jQuery代码:
jQuery(document).ready( function($){
var mediaUploader;
$('.upload-button').on('click',function(e) {
e.preventDefault();
var buttonID = $(this).data('group');
if( mediaUploader ){
mediaUploader.open();
return;
}
mediaUploader = wp.media.frames.file_frame =wp.media({
title: 'Choose a Hotel Picture',
button: {
text: 'Choose Picture'
},
multiple:false
});
mediaUploader.on('select', function(){
attachment = mediaUploader.state().get('selection').first().toJSON();
$('#profile-picture'+buttonID).val(attachment.url);
$('#profile-picture-preview'+buttonID).css('background-image','url(' + attachment.url + ')');
});
mediaUploader.open();
}); });我的PHP/HTML代码:
<input type="button" class="button button-secondary upload-button" value="Upload Profile Picture" data-group="1">
<input type="hidden" name="profile_picture1" id="profile-picture" value="'.$picture1.'">
<input type="button" class="button button-secondary upload-button" value="Upload Profile Picture" data-group="2">
<input type="hidden" name="profile_picture2" id="profile-picture" value="'.$picture2.'">任何帮助,一如既往,都是非常感谢的。
发布于 2018-09-21 06:05:32
您可以使用以下更新的HTML代码:
<input type="button" class="button button-secondary upload-button" value="Upload Profile Picture" data-group="1">
<input type="hidden" name="profile_picture1" id="profile-picture1" value="'.$picture1.'">
<input type="button" class="button button-secondary upload-button" value="Upload Profile Picture" data-group="2">
<input type="hidden" name="profile_picture2" id="profile-picture2" value="'.$picture2.'">https://stackoverflow.com/questions/52437124
复制相似问题