[英]Changing background color when highligted
您不能在文本区域中执行此操作。 您需要一个带有contentEditable
的HTML Element
。
您也可以使用CSS模拟<textarea />
。
一切如下所示:
function setColor() { document.execCommand('backColor', false, "red"); }
div[contentEditable] { -moz-appearance: textfield-multiline; -webkit-appearance: textarea; border: 1px solid gray; font: medium -moz-fixed; font: -webkit-small-control; height: 28px; overflow: auto; padding: 2px; resize: both; width: 400px; }
<div contentEditable="true">this is some text</div> <button onclick="setColor();">change color</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.