相关疑难解决方法(0)

Wordpress 3.5自定义媒体上传为您的主题选项

最近发布了Wordpress 3.5,我通过thickbox使用了Wordpress Media Upload系统,并window.send_to_editor在我的Wordpress主题(背景,徽标等)中使用了一些选项.

但是如你所知,Wordpress集成了一个新的媒体管理器,我想用这个新功能上传图像/文件作为自定义字段.所以我花了一个上午的时间来找到一种方法来获得希望的结果.

我找到了这个解决方案,这对你们中的一些人很有用.感谢您提供有关代码或您所考虑的任何改进的反馈!

HTML示例:

<a href="#" class="custom_media_upload">Upload</a>
<img class="custom_media_image" src="" />
<input class="custom_media_url" type="text" name="attachment_url" value="">
<input class="custom_media_id" type="text" name="attachment_id" value="">
Run Code Online (Sandbox Code Playgroud)

jQuery代码:

$('.custom_media_upload').click(function() {

    var send_attachment_bkp = wp.media.editor.send.attachment;

    wp.media.editor.send.attachment = function(props, attachment) {

        $('.custom_media_image').attr('src', attachment.url);
        $('.custom_media_url').val(attachment.url);
        $('.custom_media_id').val(attachment.id);

        wp.media.editor.send.attachment = send_attachment_bkp;
    }

    wp.media.editor.open();

    return false;
});
Run Code Online (Sandbox Code Playgroud)

如果您想查看attachment变量中包含的每个设置,您可以执行console.log(attachment)alert(attachment).

wordpress jquery file-upload wordpress-3.5

66
推荐指数
3
解决办法
3万
查看次数

jQuery - html字符串上的选择器

我将从一个带有jQuery的html字符串中获取一个元素,但我总是在我的控制台中得到一个未定义的元素.我的字符串是:

<td class="test">asd</td><td class="second">fgh</td><td class="last">jkl</td>
Run Code Online (Sandbox Code Playgroud)

我想获得td.test.

我测试过:

console.log($('.test', '<td class="test">asd</td><td class="second">fgh</td><td class="last">jkl</td>').innerHTML);
console.log($('.test', '<td class="test">asd</td><td class="second">fgh</td><td class="last">jkl</td>').html());
console.log($('.test', '<td class="test">asd</td><td class="second">fgh</td><td class="last">jkl</td>').first().innerHTML);
Run Code Online (Sandbox Code Playgroud)

还有一些,但没有任何作用:/

有谁知道我的问题的解决方案?

html string jquery jquery-selectors

31
推荐指数
2
解决办法
4万
查看次数