Javascript 为什么使用execCommand进行辩护不能正常工作?

Javascript 为什么使用execCommand进行辩护不能正常工作?,javascript,jquery,css,execcommand,Javascript,Jquery,Css,Execcommand,为什么使用execCommand进行辩护不能正常工作?检查以下代码: $('#justifyileft')。单击(函数(){ document.execCommand(“JustifyLeft”,false,”); }); 选择全文并单击按钮 HiIamBlah BlahOk 如果您查看开发人员工具中的元素结构,您将看到execCommand在Hi、am和Ok之后添加了关闭,并用将其包装,如下所示 <div style="text-align: left;"> &

为什么使用execCommand进行辩护不能正常工作?检查以下代码:

$('#justifyileft')。单击(函数(){
document.execCommand(“JustifyLeft”,false,”);
});

选择全文并单击按钮

HiIamBlah BlahOk
如果您查看开发人员工具中的元素结构,您将看到execCommand在Hi、am和Ok之后添加了关闭
,并用
将其包装,如下所示

    <div style="text-align: left;">
    <span style="font-style: italic; font-weight: bold; text-decoration: underline;">Hi</span>
    <span style="font-style: italic; font-weight: bold; font-size: 35px;">I</span>
    <span style="font-style: italic; font-weight: bold; text-decoration: underline;">am</span>
    <span style="font-style: italic; font-weight: bold; font-size: 18px;">Blah Blah</span>
    <span style="font-style: italic; font-weight: bold; text-decoration: underline;">Ok</span>
    </div>

您好!
我
是
废话
好 啊
您只需将第一个
更改为
即可更正它,如下所示

<div style="font-weight: bold; font-style: italic; text-decoration: underline;">Hi
<span style="font-size: 35px;">I</span>am
<span style="font-size: 18px;">Blah Blah</span>Ok
</div>
Hi
国际机械师协会
废话