[英]document.execCommand not being executed
This is a tough one for me. 对我来说这是一个艰难的过程。
Got a conentEditable div with some formating buttons. 有一些格式化按钮的conentEditable div。 One of these is a "bold" button: 其中之一是“粗体”按钮:
<li data-role="button" data-button-role="bold"><b>B</b></li>
In my javascript i got this little peace of code: 在我的JavaScript中,我得到了代码的一点点平静:
$(document).ready(function(){
$("[data-role='button'][data-button-role='bold']").click(toggleBoltFormat);
});
function toggleBoltFormat() {
document.execCommand("bold", false, null);
}
This things get called (tested with alert()), but the execCommand line is not being executed. 这些东西被调用(用alert()测试),但是execCommand行没有被执行。 So the highlighted text is not getting bold. 因此突出显示的文本不会变粗体。
Can it be a problem with relativ and absolut position of some parent element of the cE-div? cE-div的某些父元素的相对位置和绝对位置是否有问题?
When putting the docuement.execCommand line in my chromes js-console, it works fine. 将docuement.execCommand行放在我的Chrome浏览器js控制台中时,它可以正常工作。
Try to add something similar like this html's unselectable="on"
behavior. 尝试添加类似此html的unselectable="on"
行为的内容。 Created a class called unselectable and added into <li>
: 创建了一个名为unselectable的类,并将其添加到<li>
:
<li data-role="button" data-button-role="bold" class="unselectable"><b>B</b></li>
.unselectable {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.