Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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&;古腾堡如何激活更新按钮,当更改输入或文本区域值程序时_Javascript_Wordpress - Fatal编程技术网

Javascript Wordpress&;古腾堡如何激活更新按钮,当更改输入或文本区域值程序时

Javascript Wordpress&;古腾堡如何激活更新按钮,当更改输入或文本区域值程序时,javascript,wordpress,Javascript,Wordpress,我目前正在测试新的Gutenberg UI,我对一些旧代码有一些问题 当metabox中的metabox值发生编程更改时,我想激活update按钮(在我的例子中是tinymce编辑器,但我在隐藏输入时也遇到了同样的问题) jQuery不会触发真正的DOM事件,但会尝试在其内部事件映射中查找回调 另见: 因此,解决方案是通过以下方式触发事件: <script type="text/javascript"> // listen on metaboxes form jQuery(doc

我目前正在测试新的Gutenberg UI,我对一些旧代码有一些问题

当metabox中的metabox值发生编程更改时,我想激活update按钮(在我的例子中是tinymce编辑器,但我在隐藏输入时也遇到了同样的问题)


jQuery不会触发真正的DOM事件,但会尝试在其内部事件映射中查找回调

另见:

因此,解决方案是通过以下方式触发事件:

<script type="text/javascript">
// listen on metaboxes form 
jQuery(document).on('input-dirty', '.editor-meta-boxes-area form', function () {
    var $ = jQuery;
    var element = $(this)[0];
    if ("createEvent" in document) {
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent("change", false, true);
        element.dispatchEvent(evt);
    } else {
        element.fireEvent("onchange");
    }
});

// trigger event programmatically changed element
$('.your-input').closest('form').trigger('input-dirty');
</script>

//听元盒表格
jQuery(document).on('input-dirty','editor元框区域表单',函数(){
var$=jQuery;
var元素=$(此)[0];
如果(文档中的“createEvent”){
var evt=document.createEvent(“HTMLEvents”);
evt.initEvent(“变更”、假、真);
元素。调度事件(evt);
}否则{
元素。fireEvent(“onchange”);
}
});
//以编程方式更改元素的触发器事件
$('.your input')。最近('form')。触发器('input-dirty');
对于tinymce编辑器:

<?php
// or for custom tinymce editor 
$options['tinymce']['setup'] = "function (ed) {
        ed.on('blur', function (e) { // generate the content and set textarea on blur          
                                    ed.save();                                        
                                    // fix for gutenberg editor, trigger change on programmatically changed input
                                    $(ed.getElement()).closest('form').trigger('input-dirty');
                                });
                            }";
$options = array_merge(array('media_buttons' => true, 'textarea_rows' => 16, 'teeny' => true, 'quicktags' => true, 'textarea_name' => $id), $options);
wp_editor($input_text_content, $id . '_' . rand(100, 9999), $options);
?>
似乎是相关的:
<?php
// or for custom tinymce editor 
$options['tinymce']['setup'] = "function (ed) {
        ed.on('blur', function (e) { // generate the content and set textarea on blur          
                                    ed.save();                                        
                                    // fix for gutenberg editor, trigger change on programmatically changed input
                                    $(ed.getElement()).closest('form').trigger('input-dirty');
                                });
                            }";
$options = array_merge(array('media_buttons' => true, 'textarea_rows' => 16, 'teeny' => true, 'quicktags' => true, 'textarea_name' => $id), $options);
wp_editor($input_text_content, $id . '_' . rand(100, 9999), $options);
?>