我有以下部门:
<div contenteditable="true" unselectable="off" id="foo">在这个div中,我希望在每次用户输入时,使特定数量的单词看起来像、粗体、。因此,我有以下变化者:
$('#foo').live('focus', function() {
before = $(this).html();
}).live('blur keyup paste', function() {
if (before != $(this).html()) { $(this).trigger('change'); }
});
$('#foo').live('change', function() {
// make certain words bold
document.execCommand ('bold', false, null); // doesn't work
});我尝试使用document.execCommand(),但是只有当我选择要使粗体的文本时,它才能起作用。但是我不想选择文本,因为用户不知道应该是粗体的单词。
发布于 2012-11-15 21:01:06
如果不首先选择execCommand,您就不能使用它来粗体文本。
我不明白您到底在做什么,但是如果您知道要用粗体表示的单词,只需在编辑器html中使用js替换它们。
https://stackoverflow.com/questions/13406057
复制相似问题