![](/img/trans.png)
[英]How can I remove an HTML element using javascript in this specific situation
[英]How can i set html in javascript to specific location in element
我有一個像這樣的div
<div contenteditable="true" >
Hello this is content editable.... [cursor is blinking here] and more text
</div>
如何設置光標閃爍的數據。
提前致謝。
您可以將execCommand
與insertHTML
命令一起使用:
document.execCommand("insertHTML", false, "the HTML to insert");
現場示例:
$("div").on("keydown", function(e) { if (e.ctrlKey && e.which == 81) { document.execCommand("insertHTML", false, "<strong>inserted</strong>"); return false; } });
<p>Put your cursor in the relevant location below, then press Ctrl+Q:</p> <div contenteditable="true"> Hello this is content editable.... and more text </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
可悲的是,這似乎不適用於IE11。 :-| 對於跨瀏覽器的支持,您可以查看Tim Down的rangy
庫 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.