如何在CKEditor 4中设置焦点在输入元素上?

时间:2014-02-20 08:08:33

标签: javascript ckeditor

对于链接对话框,我只向用户展示了一个最小的对话框:

Screenshot

config.js文件中的代码:

CKEDITOR.on('dialogDefinition', function(ev) {
    // Take the dialog name and its definition from the event data.
    var dialogName = ev.data.name;
    var dialogDefinition = ev.data.definition;

    // Check if the definition is from the dialog we are interested in (the 'link' dialog)
    if (dialogName == 'link') {
        // Get a reference to the 'Link Info' tab.
        var infoTab = dialogDefinition.getContents('info');
        // Remove unnecessary widgets from the 'Link Info' tab.
        infoTab.remove('linkType');
        infoTab.remove('protocol');
        infoTab.remove('browse');

        // Get a reference to the "Target" tab and set default to '_blank'
        var targetTab = dialogDefinition.getContents('target');
        var targetField = targetTab.get('linkTargetType');
        targetField['default'] = '_blank';

    // focus URL field
    // targetTab.focus(); // NOT working, function does not exist
    }
}

有人能告诉我如何关注输入字段吗?

PS:我也尝试使用dialogDefinition.onShow = function () { }但没有成功。

1 个答案:

答案 0 :(得分:1)

在对话框定义中覆盖onFocus方法:

if (dialogName == 'link') {
    ....
    dialogDefinition.onFocus = function() {
        this.getContentElement( 'info', 'url' ).focus();
    }
}