首页 > Web开发 > 详细

HTML编辑器

时间:2019-11-26 22:25:26      阅读:103      评论:0      收藏:0      [点我收藏+]

<button onclick="weight()">加粗</button>
<input type="color" id="e" onchange="changeColor()" />
<input type="file" id ="f" onchange="addPicture()" />
<br/> <br/>
<div contenteditable id="d1" style="width:900px;height:500px;border:1px solid red;overflow:auto;">

</div>

<script>
function weight(){
var range = window.getSelection().getRangeAt(0);
var span = document.createElement("span");
span.style.fontWeight = 900;
range.surroundContents(span);
}

function changeColor(){
var range = window.getSelection().getRangeAt(0);
var span = document.createElement("span");
span.style.color = e.value;
range.surroundContents(span);
}

function addPicture(){
var range = window.getSelection().getRangeAt(0);
var picture = document.createElement("img");
var fileReader = new FileReader();
fileReader.readAsDataURL(f.files[0]);
fileReader.onload = function(){
picture.src = this.result;
range.insertNode(picture);
}
}
</script>

HTML编辑器

原文:https://www.cnblogs.com/lpzpp/p/11938544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!