<html>
<head>
<script>
function insertHTMLCode() {
var htmlText = '<b>HI</b>';
try {
document.execCommand('insertHTML', false, htmlText);
} catch(e) {
console.log(e);
}
}
</script>
</head>
<body>
<div>
<ys_content contenteditable="true"><!-- ~Client References -->
<font size="2" face="Arial, Helvetica, sans-serif" color="#000000"><strong>More information coming soon...</strong> </font>
<!-- ~/Client References -->
</ys_content>
</div>
<input type="button" onclick="insertHTMLCode();" value="Click">
</body>
</html>
当我尝试将HTML内容插入FireFox中的可编辑区域时,上面的代码总是抛出错误,但它在chrome中工作正常。
我的FF版本:18.0.1
答案 0 :(得分:0)
<div contenteditable="true">
<ys_content ><!-- ~Client References -->
<font size="2" face="Arial, Helvetica, sans-serif" color="#000000"><strong>More information coming soon...</strong> </font>
<!-- ~/Client References -->
</ys_content>
</div>
你的包装div应该设置为contenteditable =“true”