双击文本变输入状态
要实现的功能:从击一行文字,然后这行文字变为可编辑状态,点修改之后可以保存。
实现方案:把这一行文字放到文本框中,属性设为readonly,样式设为无边框即可。待双击事件产生后更改属性即可。
实现代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="author" content="wuleying" />
<title>双击文本变输入状态</title>
<style>
input.a {border:1px solid #fff;background:#fff;}
input.b {border:1px solid #369;background:#fff;}
</style>
</head>
<body>
<input class="a" id="test" readonly value="金飞科技[3A88.COM]" type="text" /><input type="submit" value="修改" style="display:none;" id="submit" />
<script type="text/javascript">
var test = document.getElementById("test");
var mysubmit = document.getElementById("submit");
test.ondblclick = function()
{
this.readOnly = false;
this.className = "b";
mysubmit.style.display = "";
}
mysubmit.onclick = function()
{
test.readOnly = true;
test.className = "a";
this.style.display = "none";
}
</script>
</body>
</html>
提示:点击运行代码按钮可看到实际效果
更新时间:2010-5-26
|