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

如何点击一行,得到该行文本框里的值,行的背景图片改变.
<table   width= "150 "   border= "0 "   cellspacing= "0 "   cellpadding= "0 ">
    <tr>
        <td   height= "25 "   background= "bg1.gif "> <input   name= "txt1 "   type= "text "   id= "txt1 "   size= "10 "> 中国人 </td>
    </tr>
    <tr>
        <td   height= "25 "     background= "bg1.gif "> <input   name= "txt2 "   type= "text "   id= "txt2 "   size= "10 "> 美国人 </td>
    </tr>
    <tr>
        <td   height= "25 "     background= "bg1.gif "> <input   name= "txt3 "   type= "text "   id= "txt3 "   size= "10 "> 法国人 </td>
    </tr>
</table>
<input   name= "sID "   type= "text "   id= "SID "   size= "10 ">

------解决方案--------------------
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=gb2312" />
<title>无标题文档 </title>
</head>

<body>
<table width="150" border="0" cellspacing="0" cellpadding="0" id="table1">
<tr>
  <td height="25" background="bg1.gif"> <input name="txt1" type="text" id="txt1" size="10">中国人 </td>
</tr>
<tr>
  <td height="25"  background="bg1.gif"> <input name="txt2" type="text" id="txt2" size="10">美国人 </td>
</tr>
<tr>
  <td height="25"  background="bg1.gif"> <input name="txt3" type="text" id="txt3" size="10">法国人 </td>
</tr>
</table>
<input name="sID" type="text" id="SID" size="10">
</body>
</html>
<script language="javascript">
//给表格行绑定事件的方法
function initTable(otable)
{
for(var i=0,l=otable.rows.length;i <l;i++)//遍历参数中的table的每一行
otable.rows[i].onclick = rowClick;//给点击事件添加方法
}

function rowClick()//点击事件处理方法
{
this.style.backgroundColor=this.style.backgroundColor==""?"#DDDDDD":"";//改变背景色
var inputs = this.getElementsByTagName("input");
if(inputs.length>0)
document.getElementById("sID").value = inputs[0].value;//获取输入框值
}

window.onload = function()//页面加载完毕时触发的方法
{
initTable(document.getElementById("table1"));//执行给表格行绑定事件的方法 参数是table1
}
</script>

------解决方案--------------------
code=HTML]<html>
<head>
<script>
function getValue(evt)
{
var ev=evt?evt:window.event;
var src=ev.srcEle