Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript document.execCommand(';bold';,false,true)不适用于(";click";,function(){})上的jquery_Javascript_Jquery - Fatal编程技术网

Javascript document.execCommand(';bold';,false,true)不适用于(";click";,function(){})上的jquery

Javascript document.execCommand(';bold';,false,true)不适用于(";click";,function(){})上的jquery,javascript,jquery,Javascript,Jquery,我正在尝试使用javascript和jquery进行富文本编辑 我想创建一个按钮,在一个内容可编辑的div中为所选的文本增色。当我尝试使用以下代码时,我得到了预期的结果 <div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div> <button class='bold' onclick="document.execComma

我正在尝试使用javascript和jquery进行富文本编辑

我想创建一个按钮,在一个内容可编辑的div中为所选的文本增色。当我尝试使用以下代码时,我得到了预期的结果

<div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div>
<button class='bold' onclick="document.execCommand('bold',false,true);">B</button> 

B
然而,当我使用jquery做同样的事情时,它不起作用

<div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div>
<button class='bold'>B</button>


$(function(){
    $("button.class").on("click",function(){
        document.execCommand('bold',false,true);
    })
})

B
$(函数(){
$(“button.class”)。在(“单击”,函数()上{
document.execCommand('bold',false,true);
})
})
为什么jquery不能解决我的问题

$("button.class").on("click",function(){
将此更改为

$("button.bold").on("click",function(){

这是你能做到的,我希望这一定会奏效

 $('.bold').click(function(){});

可能是因为你没有一个按钮,它的类是……
class
…哦,我真蠢!非常感谢。以后会接受你的回答(我们中最好的:)