insertRow()方法新增的行,如何为它的属性赋值 tr.onclick=function() {select(this)} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 tr.onclick=select(this)调用的select 函数吧. var tr=tblList.insertRow(tblList.rows.length);tr.setAttribute('style', 'cursor:hand');tr.setAttribute('align', 'center');... tr.onclick=function() {select(this)}没问题 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title><script> function g(v){ alert(v.cells.length); } function f(){ var newline=document.all.myt.insertRow(document.all.myt.rows.length); newline.onclick=function () {g(this);} cell0=newline.insertCell(0); cell0.innerHTML="aa"; cell0=newline.insertCell(1); cell0.innerHTML="bb"; cell0=newline.insertCell(2); cell0.innerHTML="bb"; }</script></head><body><table width="200" border="1" id="myt"> <tr onClick="g()"> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr></table><input type="button" name="Submit" value="按钮" onClick="f()"></body></html> 再完善一点,如下<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title><script> function select(v){ alert(v.cells.length); } function f(){ var newline=document.all.myt.insertRow(document.all.myt.rows.length); newline.onclick=function () {select(this);} newline.style.cursor='hand'; newline.align='center'; cell0=newline.insertCell(0); cell0.innerHTML="aa"; cell0=newline.insertCell(1); cell0.innerHTML="bb"; cell0=newline.insertCell(2); cell0.innerHTML="bb"; }</script></head><body><table width="200" border="1" id="myt"> <tr onClick="g()"> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr></table><input type="button" name="Submit" value="按钮" onClick="f()"></body></html> <script language=javascript>function select(){ alert('selected!');}function add(){ var tr=document.getElementById('t1').insertRow(); tr.style.cursor="hand"; tr.onclick=function() {select(this)} tr.insertCell().appendChild(document.createTextNode('xxx'))}</script><table border=1 id="t1"> <tr style="cursor:hand" onclick="select(this)"><td>111</td></tr></table><input type=button value="新增" onclick="add()">至于align,只能放在cell中 别的属性好像倒是能的,以前整过,但是不知道在insertRow()以后,能不能设置class(css),以前试过,一直没有找到方法啊! setAtrigute(childNodesname,vValue)即可达到 《深入浅出JavaScript》人民邮电出版社-书中例子无法运行。 请问Ext的combo控件获取的数据源是不是只能有两个字段? input框添加前缀不兼容Firefox 求解,正则表达式的疑问 简单问题:js中float大小比较 关于CSS布局的简单问 为什么有一行命令,被忽略执行了? 用javascript打开一个新jsp页面,并把一个属性传过去,急急急急!!! 关于 javascript 的问题 jquery ajax加载问题 求最简拖动层代码! 一个小问题,答对马上绐分
调用的select 函数吧.
tr.setAttribute('style', 'cursor:hand');
tr.setAttribute('align', 'center');...
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script>
function g(v){
alert(v.cells.length);
}
function f(){
var newline=document.all.myt.insertRow(document.all.myt.rows.length);
newline.onclick=function () {g(this);}
cell0=newline.insertCell(0); cell0.innerHTML="aa";
cell0=newline.insertCell(1); cell0.innerHTML="bb";
cell0=newline.insertCell(2); cell0.innerHTML="bb";
}
</script>
</head><body>
<table width="200" border="1" id="myt">
<tr onClick="g()">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="button" name="Submit" value="按钮" onClick="f()">
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script>
function select(v){
alert(v.cells.length);
}
function f(){
var newline=document.all.myt.insertRow(document.all.myt.rows.length);
newline.onclick=function () {select(this);}
newline.style.cursor='hand';
newline.align='center';
cell0=newline.insertCell(0); cell0.innerHTML="aa";
cell0=newline.insertCell(1); cell0.innerHTML="bb";
cell0=newline.insertCell(2); cell0.innerHTML="bb";
}
</script>
</head><body>
<table width="200" border="1" id="myt">
<tr onClick="g()">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="button" name="Submit" value="按钮" onClick="f()">
</body>
</html>
function select()
{
alert('selected!');
}function add()
{
var tr=document.getElementById('t1').insertRow();
tr.style.cursor="hand";
tr.onclick=function() {select(this)}
tr.insertCell().appendChild(document.createTextNode('xxx'))
}
</script><table border=1 id="t1">
<tr style="cursor:hand" onclick="select(this)"><td>111</td></tr>
</table><input type=button value="新增" onclick="add()">至于align,只能放在cell中