我有以下javascript,它涉及大约6个元素。前三个打开一个thickbox进行媒体上传,而不是单击指定的按钮,后三个目标是该媒体的src也应该转储的输入元素。
我遇到的问题是,如果我点击按钮#upload-background-image-one
然后找到我想要的媒体,单击“发送到帖子”将其插入:#background-size-three
这是第三个输入。应将其置于:#background-size-one
但事实并非如此。事实上,任何点击打开厚盒媒体上传器的按钮都会将“发送到帖子”的内容放入第三个输入框。
那么,我如何针对每个可以打开的厚盒子的特定输入?(我以为我已经是了)
Js:
( function($) {
$(document).ready(function() {
// Show WP Thickbox with image uploader.
$(\'#upload-background-image-one\').click(function() {
formfield = $(\'#background-size-one\').attr(\'name\');
tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');
return false;
});
// Take the selected image and insert only the src path into the text field.
window.send_to_editor = function(html) {
img_url = $(\'img\', html).attr(\'src\');
$(\'#background-size-one\').val(img_url);
tb_remove();
}
// Show WP Thickbox with image uploader.
$(\'#upload-background-image-two\').click(function() {
formfield = $(\'#background-size-two\').attr(\'name\');
tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');
return false;
});
// Take the selected image and insert only the src path into the text field.
window.send_to_editor = function(html) {
img_url = $(\'img\', html).attr(\'src\');
$(\'#background-size-two\').val(img_url);
tb_remove();
}
// Show WP Thickbox with image uploader.
$(\'#upload-background-image-three\').click(function() {
formfield = $(\'#background-size-three\').attr(\'name\');
tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');
return false;
});
// Take the selected image and insert only the src path into the text field.
window.send_to_editor = function(html) {
img_url = $(\'img\', html).attr(\'src\');
$(\'#background-size-three\').val(img_url);
tb_remove();
}
});
})(jQuery);