我正在开发一个Wordpress插件。使用Wordpress的上传系统。 基本上这是我上传的表单输入:
<input id="upload_image" type="text" value="" />
<input id="upload_image_button" type="button" value="Upload Image" />
其他所需的js和css文件也排队(包含在内)。最后,这个javascript包括在页面:
jQuery(document).ready(function() {
jQuery('#upload_image_button').click(function() {
formfield = jQuery('#upload_image').attr('name');
// show Wordpress' uploader modal box
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
// this will execute automatically when a image uploaded and then clicked to 'insert to post' button
imgurl = jQuery('img',html).attr('src');
// put uploaded image's url to #upload_image
jQuery('#upload_image').val(imgurl);
tb_remove();
}
});
它工作得很好,没问题。但现在我想添加一些上传表单到页面。
<input class="upload_image" type="text" value="" />
<input class="upload_image_button" type="button" value="Upload Image" />
<input id="upload_image" type="text" value="" />
<input id="upload_image_button" type="button" value="Upload Image" />
<input id="upload_image" type="text" value="" />
<input id="upload_image_button" type="button" value="Upload Image" />
我使用class="upload_image"
和class="upload_image_button"
代替id="upload_image"
和id="upload_image_button"
现在我必须更新我的javascript代码。
现在有一些上传按钮。 BUt这不起作用:
jQuery(document).ready(function() {
jQuery('.upload_image_button').click(function() {
formfield = jQuery('.upload_image_button').prev().attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
jQuery('.upload_image_button').prev().val(imgurl);
tb_remove();
}
});
我该如何更新?
答案 0 :(得分:0)
jQuery(document).ready(function() {
var clicked = null;
jQuery('.upload_image_button').click(function() {
clicked = jQuery(this);
formfield = jQuery(this).prev('input').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
clicked.prev('input').val(imgurl);
tb_remove();
}
});