javascript实现节点(div)名称编辑
节点html代码如下:
js编辑noteTxt文本,function如下:
function changeName(noteTxtId){
var noteTxt = document.getElementById(noteTxtId);
noteTxt.style.display= "none";//.style.display= "block"
var div = noteTxt.parentNode;
if(!document.getElementById("noteInput")){
var text=document.createElement("input");
text.type="text";
text.id="noteInput";
text.style.width=getStyle(noteTxt,'width');
text.style.height=getStyle(noteTxt,'height');
text.style.marginTop=getStyle(noteTxt,'marginTop');
text.style.textAlign=getStyle(noteTxt,'textAlign');
text.value=noteTxt.innerHTML;
div.appendChild(text);
text.select();
text.οnblur=function(){
noteTxt.style.display= "block";
noteTxt.innerHTML=text.value;
//text.style.display= "none";
div.removeChild(text);
}
}
}
//获得css文件中的样式
function getStyle(obj, attr)
{
if(obj.currentStyle)
{
return obj.currentStyle[attr]; //IE
}else{
return getComputedStyle(obj,false)[attr]; //FF
}
}
css如下:
.img_1 {
width: 80px;
height:70px;
position:absolute;
}
.noteText {
width:80px;
height:15px;
text-align:center;
margin-top:70px;
word-break:break-all;
}
代码非常的简单,这里就不多做解释了,下伙伴们可以自由发挥下,使用到自己的项目中去。相关阅读:
JavaScript截取、切割字符串的技巧
php json_encode值中大括号与花括号区别
Android 清除SharedPreferences 产生的数据(实例代码)
基于javascript html5实现3D翻书特效
css中使用ul li ul li ul li ul li 实现四层级联菜单
Mac怎么旋转屏幕?苹果Mac屏幕旋转设置教程
ThinkPHP添加更新标签的方法
canvas.toDataURL image/png 报错处理方法推荐
javascript动态设置样式style实例分析
完美关闭Win7屏保让屏幕一直处于正常显示状态
jsp实现从服务器下载xls文件到客户端的方法
Win10任务栏的位置不能随意调整该怎么办?
MySQL创建和删除数据库的命令及相关PHP脚本的操作方法
Php连接及读取和写入mysql数据库的常用代码