如果我在codeMirror中点击WordPress自动补全器中的一个选项,整个字段将关闭。为了防止这种情况,我想将preventDefault添加到click事件中。
var cm = wp.codeEditor.initialize( options.field, editorSettings );
var editor = cm.codemirror;
jQuery(\'body\').hover(function(e){
          if(jQuery(\'ul.CodeMirror-hints\')){
            jQuery(\'ul.CodeMirror-hints\').mousedown(function(eH){
              eH.preventDefault();
            });
          }
        });
var editorSettings = {
        mode: \'css\',
        lineNumbers: true,
        indentUnit: 2,
        tabSize: 2,
        autoRefresh:true,
        autocorrect: true,
        autocapitalize: true,
        matchBrackets: true,
        autoCloseBrackets: true,
        lineWrapping: true,
        lint: true,
        gutters: [ \'CodeMirror-lint-markers\' ]
    }
 自ul起。CodeMirror提示现在存储在body元素中,只有当CodeMirror提示提出建议时才会插入,我必须在body上生成一个事件。
body => <ul class="CodeMirror-hints"...</ul>
 是否有更好的解决方案将preventFefault()添加到单击ul的事件中。代码镜像提示?
 
                    最合适的回答,由SO网友:mrben522 整理而成
                    活动代表团是您的朋友!这样,当代码运行时,元素就不必存在,函数就可以绑定到它。
jQuery(\'body\').on(\'click\', \'ul.CodeMirror-hints li\', function(e) {
    e.preventDefault();
});
 更换
click 具有
mousedown 如果你需要的话