[英]execCommand - wrap content including tags in blockquote tags
I am trying to wrap some selected elements in <blockquote>
tags but the method I thought might work replaces the existing tags rather than wrapping them. 我试图在
<blockquote>
标签中包含一些选定的元素,但我认为可能有效的方法会替换现有的标签而不是包装它们。
Here's my code. 这是我的代码。
$("input[value='Quote']").on("click", function() {
document.execCommand('formatBlock', false, '<blockquote>');
});
and... 和...
<div contentEditable>
<p>para 1</p>
<p>para 2</p>
</div>
<input type="button" value="Quote" />
I want to end up with something like this... 我想最终得到这样的东西......
<div contentEditable>
<blockquote>
<p>para 1</p>
<p>para 2</p>
</blockquote>
</div>
rather than the following which is what I currently get... 而不是以下我目前得到的......
<div contentEditable>
<blockquote>
para 1
<br />
para 2
</blockquote>
</div>
Thanks 谢谢
This should do it 这应该做到这一点
$("input[value='Quote']").on("click", function() {
$("<blockquote/>").insertBefore($("[contenteditable]").find("p:first")).append($("[contenteditable]").find("p"))
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.