js实现编辑div节点名称的方法
作者:bea
本文实例讲述了js实现编辑div节点名称的方法。分享给大家供大家参考。具体实现方法如下: 节点html代码如下: 代码如下: <div class="img_1" id="img_1" > <input type="image" class="img_1" src="img/cump.png"></input> <div class="noteText" id="noteTxt" type="text" ondblclic
本文实例讲述了js实现编辑div节点名称的方法。分享给大家供大家参考。具体实现方法如下:
节点html代码如下:
代码如下:
<div class="img_1" id="img_1" >
<input type="image" class="img_1" src="img/cump.png"></input>
<div class="noteText" id="noteTxt" type="text" ondblclick ="changeName(this.id);">123</div>
</div>
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.onblur=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程序设计有所帮助。
有用 | 无用
节点html代码如下:
代码如下:
<div class="img_1" id="img_1" >
<input type="image" class="img_1" src="img/cump.png"></input>
<div class="noteText" id="noteTxt" type="text" ondblclick ="changeName(this.id);">123</div>
</div>
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.onblur=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程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 轻松创建nodejs服务器(4):路由
- 轻松创建nodejs服务器(3):代码模块化
- 轻松创建nodejs服务器(2):nodejs服务器的构成分析
- 轻松创建nodejs服务器(1):一个简单nodejs服务器例子
- 什么是MEAN?JavaScript编程中的MEAN是什么意思?
- 使用JS获取当前地理位置方法汇总
- node.js中的fs.chmodSync方法使用说明
- node.js中的fs.chmod方法使用说明
- 原生Ajax 和jQuery Ajax的区别示例分析
- jQuery中;function($,undefined) 前面的分号的用处
- 完美兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面js代码
- javascript实现根据身份证号读取相关信息
- node.js中的fs.appendFile方法使用说明
- javascript操作数组详解
- node.js中的fs.appendFileSync方法使用说明
- javascript实现节点(div)名称编辑
- node.js中的fs.createReadStream方法使用说明
- node.js中的fs.createWriteStream方法使用说明
- node.js中的fs.futimesSync方法使用说明