<div contentEditable="true" id="editor" /><button>加入img元素</button>不知道如何编写,才能点击按钮,在div里面插入一个图片?请用最简单,没有其他判断位置等多余代码。谢谢。
解决方案 »
- 大家帮忙看下这个click事件.怎么让它们互不相关.
- [讨论]有一表格中删除某行后其合计值却未相应减少或减少不正确
- 网站嵌套网站:如何使网页及其元素大小随区域大小改变而改变?
- JS 疑云
- 判断输入的字符串符合[5-12个数字或字母或“-”、“_”]
- 这个是不是三维数组?
- 谁能把hotmail这个对话框(窗体)源码弄出来?
- 急!父页面和子页面之间的参数怎样传递及设置问题?
- 怎样可以任意移动一个层,并始终定位于窗口的某个地方?
- 在bootstrap导航条中,在script中为了实现当前选择项高亮显示,导致href中的跳转链接失效了
- IE动态加载js 捕捉失败
- mouseOver当前元素加红框,mouseOut去掉红框,怎么做呢?
<script>
function addimg(){
var div= document.getElementById("editor");
div.innerHTML="<img><img>"//你的图片
}
</script><div contentEditable="true" id="editor" /> <input type="button" value="加入img元素" onclick=addimg()>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script type ="text/javascript" language ="javascript">
function addimg(){
var div= document.getElementById("editor");
div.innerHTML="<img src=http://album.hi.csdn.net/app_uploads/wtcsy/20090901/095636984.p.gif></img>"//这里可以是你自己本地图片的链接
}
</script>
</head>
<body>
<div id=editor></div>
<div><input type="button" value="加入img元素" onclick=addimg()></div></body>
</html>