日期:2014-05-16  浏览次数:20400 次

谁能给加个颜色 有代码 并且好使 就是想改完后能有个颜色显示
功能是这样的 一个table表格 双击后能改动其中的一个单元的内容(这段代码不是我写的) 我想改完后 那个单元能有个颜色(比如黄色) 可以么 谁能帮我改一下? 我javascript只会基础 高深的不会 下面的东西又好多都懂 只能慢慢学 现在先解决一下后顾之忧 呵呵

//f.html,父页面
<HTML>
<HEAD>
<TITLE> table页面 </TITLE>
</HEAD>
<script>
function go(event){
var event=event||window.event;
var node=event.srcElement||event.target;
var value=node.innerHTML;
var arr=new Array();
arr['value']=value;
var returnValue=window.showModalDialog('c.html',arr,'dialogWidth=400px;dialogHeight=400px');
value=returnValue||node.innerHTML;
node.innerHTML=value;
}
</script>
<BODY>
<table border='1px' cellpadding='10px' ondblclick='go(event)'>
<tr>
  <td>a</td>
  <td>b</td>
  </tr>
<tr>
  <td>c</td>
  <td>d</td>
  </tr>
<tr>
  <td>e</td>
  <td>f</td>
  </tr>
<tr>
  <td>g</td>
  <td>h</td>
  </tr>
<tr>
  <td>i</td>
  <td>j</td>
  </tr>
</table>
</BODY>
</HTML>
//c.html,子页面
<HTML>
<HEAD>
<TITLE> 修改页面 </TITLE>

<META http-equiv='content-Type' content='text/html;charset=utf-8'>

</HEAD>
<script language='javascript'>
function sure(){
var node=document.getElementsByTagName('input')[0];
window.returnValue=node.value.replace(/^\s+/g,'').replace(/\s+$/g,'');
if(window.returnValue.length>0)
window.close();
alert('不能为空');
}
function cancel(){
window.close();
}
function initC(){
var val=window.dialogArguments['value'];
document.getElementsByTagName('input')[0].value=val;
}
</script>
<BODY onload='initC()'>
<input type='text' />
<input type='button' value='确定' onclick='sure()'/>
<input type='button' value='取消' onclick='cancel()'/>
</BODY>
</HTML>

------解决方案--------------------
HTML code
<!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 type="text/javascript">
window.onload = function() {
    var obj = document.getElementById('tbl').getElementsByTagName('td');
    
    for (var i = 0; i < obj.length; i ++) {
        obj[i].ondblclick = function () {
            this.innerHTML = prompt('请输入');
            this.style.backgroundColor = 'blue';
            this.style.color = 'white';
        }
    }
}
</script>
</head>

<body>
<table width="500" border="1" id="tbl">
  <tr>
    <td>A</td>
    <td>B</td>
  </tr>
  <tr>
    <td>C</td>
    <td>D</td>
  </tr>
  <tr>
    <td>E</td>
    <td>F&l