Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript WordPress中的本地化jQuery确认按钮_Javascript_Jquery_Wordpress_Localization - Fatal编程技术网

Javascript WordPress中的本地化jQuery确认按钮

Javascript WordPress中的本地化jQuery确认按钮,javascript,jquery,wordpress,localization,Javascript,Jquery,Wordpress,Localization,我想本地化WordPress中的jQuery确认按钮。为此,我在PHP文件中编写了如下代码: function Confirmation() { // Register the script wp_register_script('eux-conf', '/js/eux-js.js'); // Localize the script with new data $translation_array = array( 'confirmation' =

我想本地化WordPress中的jQuery确认按钮。为此,我在PHP文件中编写了如下代码:

function Confirmation()
{
    // Register the script
    wp_register_script('eux-conf', '/js/eux-js.js');
    // Localize the script with new data
    $translation_array = array(
        'confirmation' => __('Confirmation', 'eux-loc'),
        'message' => __('Do you want to delete this item?', 'eux-loc'),
        'yes' => __('Yes', 'eux-loc'),
        'no' => __('No', 'eux-loc')
    );
    // Enqueued script with localized data.
    wp_enqueue_script('eux-conf');
    wp_localize_script('eux-conf', 'meta', $translation_array);
}
add_action('admin_print_scripts', 'Confirmation');
和jQuery代码:

jQuery('.delete').click(function()
{
    jQuery.confirm({
        'title': meta.confirmation,
        'message': meta.message,
        buttons: [
                    {
                        text: meta.yes,
                        classes: 'widget btn primary',
                        id: "yes",
                        onclick: function() {


                        }
                    },
                    {
                        text: meta.no,
                        classes: 'widget btn secondary',
                        id: "no",
                        onclick: 'close'
                    }
                ]

    });
编辑:在David Lee的回答之后,我意识到,如果我写
“这是一个字符串”
,而不是
meta。是的
,我会得到
0
1
,如下所示:

        buttons: [
                    {
                        text: "This is a String",
                        classes: 'widget btn primary',
                        id: "yes",
                        onclick: function() {


                        }
                    },
                    {
                        text: meta.no,
                        classes: 'widget btn secondary',
                        id: "no",
                        onclick: 'close'
                    }
                ]
我想首先,我必须纠正我的按钮参数,但我不知道

但这让我觉得:

        buttons: [
                    {
                        text: "This is a String",
                        classes: 'widget btn primary',
                        id: "yes",
                        onclick: function() {


                        }
                    },
                    {
                        text: meta.no,
                        classes: 'widget btn secondary',
                        id: "no",
                        onclick: 'close'
                    }
                ]

你看,我的按钮是
Yes
No
,但代码显示
0
1
。如何更正此问题?

试试看

function Confirmation()
{
    // Register the script
    wp_register_script('eux-conf', '/js/eux-js.js');
    // Localize the script with new data
    $translation_array = array(
        'confirmation' => __('Confirmation', 'eux-loc'),
        'message' => __('Do you want to delete this item?', 'eux-loc'),
        'yes_s' => __('Yes', 'eux-loc'),
        'no_s' => __('No', 'eux-loc')
    );
    // Enqueued script with localized data.
    wp_localize_script('eux-conf', 'meta', $translation_array);//this one first
    wp_enqueue_script('eux-conf');

}
add_action('admin_enqueue_scripts', 'Confirmation');
在jQuery中:

jQuery('.delete').click(function()
{
    jQuery.confirm({
        'title': meta.confirmation,
        'message': meta.message,
        buttons: [
                    {
                        text: meta.yes_s,
                        classes: 'widget btn primary',
                        id: "yes",
                        onclick: function() {


                        }
                    },
                    {
                        text: meta.no_s,
                        classes: 'widget btn secondary',
                        id: "no",
                        onclick: 'close'
                    }
                ]

    });
我更改了顺序,您需要先本地化,然后
排队
,我还将钩子更改为
管理队列脚本
,并更改了变量的名称,因为
是保留变量。

尝试

jQuery.confirm({
    'title': meta.confirmation,
    'message': meta.message,
    buttons: {
        yes: {
            text: meta.yes_s, // OR text: "'"+meta.yes_s+"'",
            classes: 'widget btn primary',
            id: "yes",
            onclick: function() {

            }
        },
        no: {
             text: meta.no_s, // OR text: "'"+meta.no_s+"'",
             classes: 'widget btn secondary',
             id: "no",
             onclick: 'close'
        },
    }
});

jqueryconfirm只是一个插件,而不仅仅是一个插件。还有一个名为jQuery.confirm的插件。哪一个是你的插件或其他插件。我建议更新你的插件。因为Jaydip Nimavat的例子是有效的。

一行中有一个打字错误-
wp\u register\u脚本('eux-conf',/js/eux js.js')
缺少引号,应该是
wp\u register\u脚本('eux-conf','/js/eux js.js')(在第二个参数之前引用)。@JackBashford,谢谢,这是一个复制粘贴错误。我正在编辑。不幸的是,结果没有改变。。。现在我意识到,如果你写
这是一个字符串,而不是
meta。是的,你会再次得到
0
1
。你能做
console.log(meta)吗并将其显示到您的问题中?