0
我有一個contenteditable div。當用戶在其中粘貼文本時。它帶有html標籤,我想刪除除b,i,u,blockquote,h3標籤之外的所有標籤。在contenteditable div中刪除jQuery的一些標籤
我該如何做到這一點? 謝謝你的幫助。
我有一個contenteditable div。當用戶在其中粘貼文本時。它帶有html標籤,我想刪除除b,i,u,blockquote,h3標籤之外的所有標籤。在contenteditable div中刪除jQuery的一些標籤
我該如何做到這一點? 謝謝你的幫助。
var ignoreTags = "b, i, u, blockquote, h3";
$("[contenteditable]").on({
paste : function() {
setTimeout(function(){
$(this).find("*").not(ignoreTags).contents().unwrap();
}.bind(this), 0);
}
});
p{color: blue;}
[contenteditable]{background:#eee;padding:16px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>H2. Unwrap me.</h2>
<h3>H3. Keep me.</h3>
<blockquote>blockquote</blockquote>
<p>Unwrap Paragraph but keep <b>bold</b> and <i>italic</i></p>
<div contenteditable>pasteHere</div>
請仔細閱讀[問]比最終爲我們提供一些代碼用[MCVE。如果你還不清楚這個網站是如何工作的,一定要參加[參觀]。 –