document.execCommand不保留单击事件

时间:2019-03-28 19:15:58

标签: jquery

我试图通过单击按钮来加粗文本。我在JS Fiddle中创建了它,并且效果很好。但是,问题是当我将脚本放在网页上时。它执行操作,但不保留点击事件

https://jsfiddle.net/lvwiseguy/v7jm03zu/7/

<head runat="server">
    <title></title>
    <script src="jquery-3.3.1.js"></script>
    <script>
        $(document).ready(function() {
            $('#BoldText').click(function () {
                document.execCommand('bold');
            });
        });
    </script>
    <style>
        #editable_textarea {
          width: 100%;
          height: 150px;
          border: 1px solid blue;
        }

        button {
          font-weight: bold;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <button id="BoldText">B</button>
        <div id='editable_textarea' contenteditable="true">
          Select text and click the button to make it bold...
        </div>
    </form>
</body>

0 个答案:

没有答案