contentEditable ExecCommand“粗体”无法触发

问题描述 投票:3回答:1

我在contentEditable div上执行执行命令“大胆”时遇到很多麻烦。对于类似的问题,我尝试了很多解决方案,但均无济于事。我知道execCommand有一些错误;任何帮助将不胜感激!

这是我的代码:

$("#bolder").on('click', function() {
    document.execCommand("bold", false, null);
});
.text {
    	position: relative;
    	width: 100%;
    	height: 90%;
    	left: 0%;
    	border: solid;
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="body">
    <button id="bolder" type="button">Bold</button>
	<div class="text"  contenteditable="true">
			This won't work	
	</div>
	<img class="loader" id="loader" src="Social_Icons/loader.svg">
</div>

我正在使用最新的Chrome浏览器。

javascript jquery html css contenteditable
1个回答
1
投票

您的代码运行正常。但是:

© www.soinside.com 2019 - 2024. All rights reserved.