jQuery窗口.send_to_editor [英] Jquery window.send_to_editor

查看:52
本文介绍了jQuery窗口.send_to_editor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为此无法拿出一个好标题.

Couldn't come up with a good title for this.

我在WordPress中建立了一个版本,其中使用内置的WordPress媒体上载器上传了多个图片.工作原理是,在您上传并选择插入"后,jQuery将图像路径插入包含ID的文本字段中.保存后,文本字段将保存在选项表中.

I've got a build in WordPress where I have multiple image uploads using the built in WordPress media uploader. How it's working is, after you upload and choose "insert", jQuery is inserting the image path into a text field, which contains the ID. Once you save, the text field is saved in the options table.

如果只有1个上传字段,则效果很好.添加更多上载后,每个上载字段都将使用相同的图像路径保存.只需每个上传按钮仅为其关联的文本字段插入值即可.

Works perfectly if you only have 1 upload field. Once you add more uploads, every upload field gets saved with the same image path. Just need each upload button to only insert the value for it's associated text field.

我尝试使用.each,但无法使其正常工作.还尝试对值插入使用.attr('id'),但没有执行任何操作.

I've tried to use .each but couldn't get it working correctly. Also tried using .attr('id') to the value insert, but nothing doing there.

这是我的jQuery和标记:

Here is my jQuery and the markup:

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>

有关更多信息,这是我使用的上载程序设置:

For further info, here is the uploader setup I'm using: http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/

非常感谢您一如既往的帮助.

Any help, as always, is greatly appreciated.

推荐答案

只需要能够指定将值插入到其中的输入字段即可.

Just need to be able to specify the input field that the value is inserted into.

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('', 'media-upload.php?type=image&amp;TB_iframe=true');
    return false;
});

window.send_to_editor = function(html) {
    imgurl = jQuery('img',html).attr('src');
    uploadID.val(imgurl); /*assign the value to the input*/
    tb_remove();
};

这篇关于jQuery窗口.send_to_editor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆