Javascript 在可编辑的div中使用jqueryclick事件

Javascript 在可编辑的div中使用jqueryclick事件,javascript,jquery,html,events,text,Javascript,Jquery,Html,Events,Text,我使用JQuery为不同的标记注册事件。以下是迄今为止的代码: <!DOCTYPE html> <html> <head> <script src="jquery-1.7.js"></script> </head> <body> <p>First Paragraph</p> <p>Second Parag

我使用JQuery为不同的标记注册事件。以下是迄今为止的代码:

<!DOCTYPE html>
<html>
    <head>
        <script src="jquery-1.7.js"></script>
    </head>
    <body>
        <p>First Paragraph</p>

        <p>Second Paragraph</p>
        <p>Yet one more Paragraph</p>

        <div><p>another one</p></div>

        <p><strong>big one</strong></p>

        <div contentEditable="true"><p>hello <b>there</b></p></div>

        <script>
            $("p").click(function () { 
                         alert('p tag'); 
                         });

            $("div").click(function () { 
                         alert('div tag'); 
                         });

            $("b").click(function () { 
                         alert('strong tag'); 
                         });

            </script>

    </body>
</html>

第一段

第二段

还有一段

另一个

大的

你好

$(“p”)。单击(函数(){ 警报(“p标签”); }); $(“div”)。单击(函数(){ 警报(“div标签”); }); $(“b”)。单击(函数(){ 警报(“强标记”); });
我想开发一个简单的文本编辑器,并希望捕获点击事件,以便更新按钮的状态(粗体、斜体等)。我希望单击事件也能在可编辑的div内工作,但它们仅在选择div标记时触发一次,然后在编辑开始时,单击该div内的任何位置都不会触发,即使我在div内有p和b标记。是否可以使用可编辑div实现这一点?基本上,我希望能够知道光标是在b标记还是在I标记内,以便更新按钮的状态。

您可以使用

你可以用

$("editableDIV").one("click",function(){...});