document.execCommand("insertHTML",false,value);这个方法在firefox在不能支持,有谁知道怎么办吗?
demo代码在这里.请用firefox打开.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body>
<input id="input" type="text"/>
<button onclick="getText(this);">文字</button>
<script>
var input = document.querySelector("input")
function getText(tz){
input.focus();
document.execCommand("insertHTML", false, tz.innerHTML);
//这样才能触发change
input.blur();
return false;
}
</script>
</body>
</html>
相关分类