我一直在做一个文本编辑器,但是我无法在具有可编辑内容的div中将“光标”设置到一个新位置。
<form action="submitchapter.php" method="post"> <div class="input-group mb-3" style="margin-top:30px;"> <input type="text" class="form-control name" placeholder="Chapter Name" name="sname" value="No Title For The Chapter" required> </div> <div class="buttons shadow-sm"> <button style="padding:0; border:0px solid white; background-color:white;" type="button" id="buttonbold"><i class="fas fa-bold" id="bold"></i></button> <input id="file-input" type="file" name="name" style="display: none;" /> </div><br> <div class="containe shadow-sm" style="padding:20px; background-color:white;"> <div class="content" contenteditable="true" name="content" id="content" role="textbox" spellcheck="false"></div> </div>
var content = document.getElementById("content"); var bold = document.getElementById("bold"); var content = document.getElementById("content"); $("#buttonbold").click(function(){ content.focus(); var valuelength = content.value.length - 4; content.setSelectionRange(content.value.length,valuelength); }); var boldactive = false; $("#bold").click(function(){ if (boldactive == false) { var content1 = content.innerHTML; content.innerHTML = content1 + "<b>"; boldactive = true; } else { var content1 = content.innerHTML; content.innerHTML = content1 + "</b>"; boldactive = false; } });
但是没有任何效果。我也尝试过textarea,但我认为我做错了。
我一直在做一个文本编辑器,但是我无法在内容可编辑的div中获取并设置“光标”在新位置。
[<div>
元素没有value
属性