简体   繁体   English

contentEditeable和document.execCommand('bold',..)的问题

[英]Issues with contentEditeable and document.execCommand('bold',..)

I am allowing some small inline editing on my blogpost page with the following code: 我允许在博客文章页面上使用以下代码进行一些小的内联编辑:

BlogEditor.prototype.applyBindings = function(argument){
    var makeBoldProxy = $.proxy(this.makeBold, this);
    var enableEditingProxy = $.proxy(this.enableEditing,this);
    this.boldButton.bind('click', makeBoldProxy);
    this.enableEditingButton.bind('click', enableEditingProxy);
};

BlogEditor.prototype.enableEditing = function(argument){
    $('#blogContent *').attr('contenteditable','true');
    this.isEditing = true;
    this.toggleControls();
};

BlogEditor.prototype.makeBold = function(argument){
    if(!this.isEditing){
        return;
    }
    document.execCommand ('bold', false, null);
};

the makeBold statemtent is called (locally i have some logs in there to check). makeBold statemtent被调用(在本地我有一些日志要检查)。

Problem The selected text is not made bold. 问题所选文本未加粗体。 Any ideas why this is not working? 任何想法为什么这不起作用?

the problem seems to be html5, the functionality works perfectly i realised, but the browser wont show the tags in bold anymore .. 问题似乎是html5,我实现了该功能,但浏览器不再以粗体显示标签了。

What web browser are you using? 您正在使用什么网络浏览器?

Take a look at this page, this works for chrome/firefox/safari: 看看此页面,此页面适用于chrome / firefox / safari:

https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand https://developer.mozilla.org/zh-CN/docs/Web/API/Document/execCommand

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM