【问题标题】:Metabox Wordpress plugin Thickbox jQuery error- Uncaught TypeError: Cannot read property 'replace' of undefinedMetabox Wordpress 插件Thickbox jQuery 错误 - Uncaught TypeError: Cannot read property 'replace' of undefined
【发布时间】:2016-06-01 21:47:37
【问题描述】:

我在 Wordpress 中使用 Metabox 插件,它带有thickbox 选项。

一切正常,除了尝试使用多张图片上传创建/编辑画廊。

当我点击“插入图库”按钮时,什么也没有发生,我在 chrome 控制台中注意到:

Uncaught TypeError: Cannot read property 'replace' of undefined

文件内容如下

jQuery( function ( $ )
{
    'use strict';

    $( 'body' ).on( 'click', '.rwmb-thickbox-upload', function ()
    {
        var $this = $( this ),
            $holder = $this.siblings( '.rwmb-images' ),
            post_id = $( '#post_ID' ).val(),
            field_id = $this.data( 'field_id' ),
            backup = window.send_to_editor;

        window.send_to_editor = function ( html )
        {
            var $img = $( '<div />' ).append( html ).find( 'img' ),
                url = $img.attr( 'src' ),
                img_class = $img.attr( 'class' ),
                id = parseInt( img_class.replace( /\D/g, '' ), 10 );

            html = '<li id="item_' + id + '">';
            html += '<img src="' + url + '">';
            html += '<div class="rwmb-image-bar">';
            html += '<a class="rwmb-delete-file" href="#" data-attachment_id="' + id + '">×</a>';
            html += '</div>';
            html += '<input type="hidden" name="' + field_id + '[]" value="' + id + '">';
            html += '</li>';

            $holder.append( $( html ) ).removeClass( 'hidden' );

            tb_remove();
            window.send_to_editor = backup;
        };
        tb_show( '', 'media-upload.php?post_id=' + post_id + '&TB_iframe=true' );

        return false;
    } );
} );

这是给出错误的行

id = parseInt( img_class.replace( /\D/g, '' ), 10 );

【问题讨论】:

  • 您好,您找到解决此问题的方法了吗?好像没有人这么看。如果您能分享这个问题的前进方向,将不胜感激,谢谢。
  • @user3619389 - 我现在也遇到同样的错误,到目前为止似乎找不到主要问题。
  • 我也找不到问题,我用其他方法来克服这个不是元框,...

标签: php jquery wordpress


【解决方案1】:

这个错误是因为 html 没有 img 标签... 将您的代码更改为:

var $img = $( '<div />' ).append( html ).find( 'i' );
url = $img.attr( 'src' ),
img_class = $img.attr( 'class' ),
id = parseInt( img_class.replace( /\D/g, '' ), 10 );

【讨论】:

    猜你喜欢
    • 2021-03-16
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2019-02-12
    • 2021-09-20
    • 2021-06-08
    相关资源
    最近更新 更多