我如何让它工作-从厚厚的盒子发送到邮寄

时间:2015-01-13 作者:TheWebs

我有以下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);

1 个回复
SO网友:TheWebs

正确的方法是:

    $(\'#upload-background-image-one\').click(function() {
        formfield = $(\'#background-size-one\').attr(\'name\');
        tb_show(\'\', \'media-upload.php?type=image&TB_iframe=true\');

        // 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();
        }

        return false;
    });
因为当您单击一个按钮时,您可以实例化一个回调函数,您可以在该函数中执行所有操作。然后范围与该功能相关联

结束

相关推荐

使用MEDIA_HANDLE_UPLOAD上载具有多个字段的多个文件

我问this question 大约几天前,答案立即解决了我的问题,但现在,当我尝试在表单中放置许多文件字段时,这只是第一次实地工作,因为我之前问题的解决方案覆盖了$\\u FILES数组。现在,我的表单中有以下HTML:<input type="file" name="my_file_upload[]" id="my_file_upload[]" multiple="multiple"> <inpu