js如何对input动态赋值?

myhai 2010-05-17 05:52:08
<!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" />
<title>无标题文档</title>
<script language="JavaScript">
function Edit(sender)
{
if(!sender.lastChild || sender.lastChild.tagName != "TEXTAREA")
{
var box = document.createElement("textarea");
box.style.cssText = "background-color:transparent;border:none; font:14px 宋体;margin:-2pt -1pt;width:100%; overflow:hidden";
box.rows = 1;
if(sender.align) box.style.textAlign = sender.align;
box.defaultValue = box.value = sender.innerText;
sender.innerHTML = "";
sender.appendChild(box);
box.onpropertychange = function()
{
if(this.value) this.style.posHeight = this.scrollHeight;
}
box.onblur = function()
{
if(this.value == this.defaultValue)
{
sender.innerText = this.value;
sender.bgColor = "";
}
}
box.focus();
sender.bgColor = "#effbff";
}
}
</script>
</head>

<body>
<input name="aa1" type="hidden" value="" />
<input name="aa2" type="hidden" value="" />
<input name="aa3" type="hidden" value="" />
<table width="200" border="1">
<tr>
<td onclick="Edit(this,'aa1')"> </td>
<td onclick="Edit(this,'aa2')"> </td>
<td onclick="Edit(this,'aa3')"> </td>
</tr>
</table>
</body>
</html>
...全文
1058 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
passself 2010-05-18
  • 打赏
  • 举报
回复

<!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=utf-8" />
<title>测试</title>

<script language="JavaScript">
function Edit(sender,id)
{
if(!sender.lastChild || sender.lastChild.tagName != "TEXTAREA"){
var box = document.createElement("textarea");
box.style.cssText = "background-color:transparent;border:none; font:14px 宋体;margin:-2pt -1pt;width:100%; overflow:hidden";
box.rows = 1;
if(sender.align) box.style.textAlign = sender.align;
box.defaultValue = box.value = document.getElementById(id).value;//sender.innerText;
sender.innerHTML = "";
sender.appendChild(box);
box.onpropertychange = function(){
if(this.value) this.style.posHeight = this.scrollHeight;
}
box.onblur = function(){
if(this.value == this.defaultValue){
sender.innerText = this.value;
sender.bgColor = "";
}
}
box.focus();
sender.bgColor = "#effbff";
}
}
</script>
</head>

<body>
<input name="aa1" id="aa1" type="hidden" value="gggg" />
<input name="aa2" id="aa2" type="hidden" value="hello" />
<input name="aa3" id="aa3" type="hidden" value="hi" />
<table width="200" border="1">
<tr>
<td onclick="Edit(this,'aa1')"> </td>
<td onclick="Edit(this,'aa2')"> </td>
<td onclick="Edit(this,'aa3')"> </td>
</tr>
</table>
</body>
</html>


建议用id
  • 打赏
  • 举报
回复
inputNode.setAttribute('value','xxxxxx');
inputNode.value='xxxxxx';
input是不会刷新的新值不会被显示在页面中
happy664618843 2010-05-17
  • 打赏
  • 举报
回复
if(event.srcElement.type=="input"){
event.srcElement.value="aa";
}
nobody@noone 2010-05-17
  • 打赏
  • 举报
回复
直接改input的value
xiaofan_sap 2010-05-17
  • 打赏
  • 举报
回复
有点不明白啊
myhai 2010-05-17
  • 打赏
  • 举报
回复
动态赋值,不固定的

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧