I'm having a problem with jQuery that I thought would be simple, but I still haven't found a solution.
I have an upload form for users to upload images in WordPress, and when a user clicks "insert into post" the url of the uploade开发者_如何学运维d image is supposed to go into a text input field.
I can get 1 to work fine, but when I have multiple upload buttons with multiple input fields the image url is send to the last text input only.
Here's my code:
<script type="text/javascript">
//MEDIA UPLOADER
jQuery(document).ready(function() {
//Opens the upload dialog box when the button is clicked
jQuery('#wpsa_slide_<?php echo $slidenumber; ?>_button').click(function() {
formfield = jQuery('#wpsa_slide_<?php echo $slidenumber; ?>').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
//Sends the uploaded/selected file URL to the text input field
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('#wpsa_slide_<?php echo $slidenumber; ?>').val(imgurl);
tb_remove();
}
});
</script>
imgurl = jQuery('img',html).attr('src');
This selects all the images in your html and gets the src attribute of the first one in this collection. Probably the problem is there...
jQuery(document).ready(function()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length+1;
var row=0;
var click=0;
for(var num=0;num<lastRow;num++)
{
row+=1;
jQuery('#upload_image_button'+row).click(function() {
formfield = jQuery('#my_meta[image'+row+']').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
click=this.id;
return false;
});
}
window.send_to_editor = function(html) {
click = click.substring(19);
imgurl = jQuery('img',html).attr('src');
var field = 'upload_image_hide'+click+'';
jQuery('#'+field).val(imgurl);
tb_remove();
}
});
精彩评论