微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Jquery window.send_to_editor

不能拿出一个很好的称号.

我已经在wordpress中建立了一个使用内置的wordpress媒体上传器的多个图像上传.它的工作原理是,在您上传并选择“插入”后,jQuery将图像路径插入到包含ID的文本字段中.保存后,文本字段将保存在选项表中.

如果您只有1个上传字段,则可以正常工作.添加更多上传内容后,每个上传字段都将以相同的图像路径保存.只需要每个上传按钮才能插入相关文本字段的值.

我试图使用.each但无法使其正常工作.也尝试使用.attr(‘id’)到值insert,但没有做任何事情.

这是我的jQuery和标记

jQuery('.upload-button').click(function() {
    formfield = jQuery('.upload').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').val(imgurl);
    tb_remove();
};

<div class="upload_field"
    <input type="text" name="upload_one" id="upload_one" class="upload" value="" />
    <input type="button" class="upload-button" value="Upload Image" />
</div>

<div class="upload_field"
    <input type="text" name="upload_two" id="upload_two" class="upload" value="" />
    <input type="button" class="upload-button" value="Upload Image" />
</div>

<div class="upload_field"
    <input type="text" name="upload_three" id="upload_three" class="upload" value="" />
    <input type="button" class="upload-button" value="Upload Image" />
</div>

更多信息,这里是我使用的上传器设置:http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/

任何帮助,一如既往,非常感谢.

解决方法

只需要能够指定该值被插入的输入字段.
var uploadID = ''; /*setup the var*/

jQuery('.upload-button').click(function() {
    uploadID = jQuery(this).prev('input'); /*grab the specific input*/
    formfield = jQuery('.upload').attr('name');
    tb_show('',html).attr('src');
    uploadID.val(imgurl); /*assign the value to the input*/
    tb_remove();
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐