<table id=hrong border=1 width=300>
<tr><td>黄1</td><td>蓉1</td></tr>
<tr><td>黄2</td><td>蓉2</td></tr>
<tr><td>黄3</td><td>蓉3</td></tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
function searchObjByTagName(obj, tag)
{
while(obj!=null && typeof(obj.tagName) != "undefind")
{
if(obj.tagName == tag.toUpperCase()) return(obj);
obj = obj.parentElement;
}
return null;
}
document.all.hrong.attachEvent("onclick", function(){
var e = window.event.srcElement;
var td = searchObjByTagName(e, "td");
alert(td.innerText);
});
</SCRIPT>
<tr><td>黄1</td><td>蓉1</td></tr>
<tr><td>黄2</td><td>蓉2</td></tr>
<tr><td>黄3</td><td>蓉3</td></tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
function searchObjByTagName(obj, tag)
{
while(obj!=null && typeof(obj.tagName) != "undefind")
{
if(obj.tagName == tag.toUpperCase()) return(obj);
obj = obj.parentElement;
}
return null;
}
document.all.hrong.attachEvent("onclick", function(){
var e = window.event.srcElement;
var td = searchObjByTagName(e, "td");
alert(td.innerText);
});
</SCRIPT>
解决方案 »
- js动态添加标签时怎样添加有动态参数的onclick事件,新手求教??
- 参数传递问题
- 比较急,为何jquery easyui创建的menu中的submenu无法点击?
- 怎么样在日历中加入链接?
- 请教:有什么方法用jQuery插件tooltip给图片增加提示?
- 怎么获得div的大小?
- 想实现一个功能 当选择表单select0里边的“产品分类“,然后自动探出另外一个select1表单,选择select1表单里边的分类信息搜索,选择表单
- 如何实现两个计时器?
- 在浏览器中,avi,rm,asf,wmv,mpeg,mov,ipix等格式的文件怎么打开,需要什么插件,在线等,提供信息就给分
- 怎样在一个具有框架的窗口中关闭浏览器?
- 如何在客户端脚本中调用用户本地的应用程序并传递参数?解决者分全给
- 重要问题===========仅在html 帮助中才有此功能==================
(1).用鼠标双击table A某一行,然后把这行中的所有单元格的值付给另一个table B;(我现在的问题是当鼠标选中这行时不知如何表示这行的每一个单元格的值)(2).然后在table B中修改这些值,之后按一个按钮可把这些值再存回table A中的原行。下面是我的代码:
<html><head></head><body>
<script>
function a(o)
{
o.bgColor="#FF00FF"
}function b(o)
{
o.bgColor="#3399FF"
}
function tiqu(o)
{
这里边要实现提取这行的值并付给tableB}
</script> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="tableA">
<tr onclick='tiqu(this)' style='cursor:hand' onmouseover='a(this)' onmouseout='b(this)'>>
<td width="20%">设备类型</td>
<td width="36%">设备名称</td>
<td width="20%">设备型号</td>
</tr>
</table>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="tableB">
<tr >
<td width="20%"><input type="text" name="T1" size="20"></td>
<td width="36%"><input type="text" name="T1" size="20"></td>
<td width="20%"> <input type="button" value="保存" name="B3"></td>
<td width="20%"> </td>
<td width="36%"> </td>
<td width="20%"> </td>
</tr>
<tr >
<td width="20%"><input type="text" name="T1" size="20"></td>
<td width="36%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="36%"> </td>
<td width="20%"> </td>
</tr>
</table>
</body></html>
<script>
function a(o)
{
o.bgColor="#FF00FF"
}function b(o)
{
o.bgColor="#3399FF"
}
function tiqu(o)
{alert(o.cells[0].innerText);
alert(o.cells[1].innerText);
alert(o.cells[2].innerText);
}
</script> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="tableA">
<tr onclick='tiqu(this)' >
<td width="20%">设备类型</td>
<td width="36%">设备名称</td>
<td width="20%">设备型号</td>
</tr>
<tr onclick='tiqu(this)' style='cursor:hand' onmouseover='a(this)' onmouseout='b(this)'>
<td width="20%">类型1</td>
<td width="36%">名称1</td>
<td width="20%">型号1</td>
</tr>
</table>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="tableB">
<tr >
<td width="20%"><input type="text" name="T1" size="20"></td>
<td width="36%"><input type="text" name="T1" size="20"></td>
<td width="20%"> <input type="button" value="保存" name="B3"></td>
<td width="20%"> </td>
<td width="36%"> </td>
<td width="20%"> </td>
</tr>
<tr >
<td width="20%"><input type="text" name="T1" size="20"></td>
<td width="36%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="36%"> </td>
<td width="20%"> </td>
</tr>
</table>
</body></html>
<html><head></head><body>
<script>
function a(o)
{
o.bgColor="#FF00FF"
}function b(o)
{
o.bgColor="#3399FF"
}
function tiqu(o)
{
document.main.tu.value=o.rowIndex;
document.main.T1.value=o.cells[0].innerText;
document.main.T2.value=o.cells[1].innerText;
document.main.T3.value=o.cells[2].innerText;}
function mo()
{
document.all.tableA.rows[document.main.tu.value].cells[0].innerText=document.main.T1.value;
document.all.tableA.rows[document.main.tu.value].cells[1].innerText=document.main.T2.value;
document.all.tableA.rows[document.main.tu.value].cells[2].innerText=document.main.T3.value;
}
</script>
<form name="main" >
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="tableA">
<tr onclick='tiqu(this)' >
<td width="20%">设备类型</td>
<td width="36%">设备名称</td>
<td width="20%">设备型号</td>
</tr>
<tr onclick='tiqu(this)' style='cursor:hand' onmouseover='a(this)' onmouseout='b(this)'>
<td width="20%">类型1</td>
<td width="36%">名称1</td>
<td width="20%">型号1</td>
</tr>
<tr onclick='tiqu(this)' style='cursor:hand' onmouseover='a(this)' onmouseout='b(this)'>
<td width="20%">类型2</td>
<td width="36%">名称2</td>
<td width="20%">型号2</td>
</tr>
</table>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="tableB">
<tr >
<td width="20%"><input type="text" name="T1" size="20"></td>
<td width="36%"><input name="T2" type="text" id="T2" size="20"></td>
<td width="20%"> <input type="button" value="保存" name="B3" onClick="mo()"></td>
<td width="20%"> </td>
<td width="36%"> </td>
<td width="20%"><input name="tu" type="text" id="tu"> </td>
</tr>
<tr >
<td width="20%"><input name="T3" type="text" id="T3" size="20"></td>
<td width="36%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="36%"> </td>
<td width="20%"> </td>
</tr>
</table>
</form>
</body></html>
<body>
<script>
function a(o)
{
o.bgColor="#FF00FF"
}function b(o)
{
o.bgColor="#3399FF"
}
function tiqu(o)
{
alert(o.cells[0].innerText);
alert(o.cells[1].innerText);
alert(o.cells[2].innerText);
}function addrow()
{
*****这里插入的一行如何实现与原有行相同的功能,也就是如何控制新插入行的属性****objTable = document.all.item("tableA"); //table1是需要操作的表格名字
newRow = objTable.insertRow(); //表示从1行前插入newCell = newRow.insertCell(); //插入单元格,可以重复使用插入多个
newCell.innerText="dd";newCell = newRow.insertCell(); //插入单元格,可以重复使用插入多个newCell.innerText="d";
newCell = newRow.insertCell(); //插入单元格,可以重复使用插入多个
newCell.innerText ="FF";}
</script> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="tableA">
<tr onclick='tiqu(this)' >
<td width="20%">设备类型</td>
<td width="36%">设备名称</td>
<td width="20%">设备型号</td>
</tr>
<tr onclick='tiqu(this)' style='cursor:hand' onmouseover='a(this)' onmouseout='b(this)'>
<td width="20%">类型1</td>
<td width="36%">名称1</td>
<td width="20%">型号1</td>
</tr>
</table>
<p><input type="button" value="按钮" name="B3" onclick="addrow()"></p>
</body></html>谢谢了!