禁用新的blockquote contenteditable

如果在COntentent可编辑javascript或jQuery上输入keypress,则禁用新的blockquote

HTML

This is a paragraph. Lorem Ipsum...

This is a blockquote. Enter here

CSS

 blockquote { background: beige; padding: 10px; border: 2px dashed #dadada; } 

片段

 blockquote { background: beige; padding: 10px; border: 2px dashed #dadada; } 
 

This is a paragraph. Lorem Ipsum...

This is a blockquote. Enter here

Ans基于这个旧的如此ans。 。 对ans进行了略微修改。

 $('#demo').keypress(function(e) { var key = e.which; if (key == 13) // the enter key code { var input = document.getElementById('demo'); if (whichTag("blockquote")) { document.execCommand('InsertParagraph'); document.execCommand('Outdent'); } } }); function whichTag(tagName) { var sel, containerNode; var tagFound = false; tagName = tagName.toUpperCase(); if (window.getSelection) { sel = window.getSelection(); if (sel.rangeCount > 0) { containerNode = sel.getRangeAt(0).commonAncestorContainer; } } else if ((sel = document.selection) && sel.type != "Control") { containerNode = sel.createRange().parentElement(); } while (containerNode) { if (containerNode.nodeType == 1 && containerNode.tagName == tagName) { tagFound = true; containerNode = null; } else { containerNode = containerNode.parentNode; } } return tagFound; } 
 blockquote { background: beige; padding: 10px; border: 2px dashed #dadada; } 
  

This is a paragraph. Lorem Ipsum...

This is a blockquote. Enter here