您现在的位置是:首页 > 电脑技术查询 > web开发

关于使用javascript自动添加表格后给单元格赋行为的有关问题

编辑:chaxungu时间:2022-10-02 23:22:25分类:web开发

关于使用javascript自动添加表格后给单元格赋行为的问题
使用
row = tbl.insertRow();
cell = row.insertCell();
添加行和列之后,如何给行和列赋行为,我使用row.onMouseOver = fun();之后,在fun()中加入alert( "test ");测试发现每次添加行或者列之后都会调用这个函数,但是当我鼠标移动到该行之后却无法引发行为。
不想在cell中加入 <div onMouseOver= "fun() "> text </div> 这样的语句,请问如果添加。
谢谢各位先。

------解决方案--------------------
<script type= "text/javascript ">
function dd(){
var a=document.getElementById( "tab ")
row = a.insertRow();
cell = row.insertCell();
cell.innerText= "11111111111 "
row.onmouseover=func

}

function func(){
alert( "?? ")
}
</script>
<input type= "button " value= "press " onclick= "dd() ">
<table id= "tab ">
------解决方案--------------------
function dd(){
var a=document.getElementById( "tab ")
row = a.insertRow();
cell = row.insertCell();
cell.innerText= "11111111111 "
row.onmouseover=function(){func11( "3333 ")}

}

function func(){
alert( "?? ")
}
function func11(a){
alert(a)
}
</script>
<input type= "button " value= "press " onclick= "dd() ">
<table id= "tab ">


</table>
------解决方案--------------------
或者attachEvent( "onmouseover ",function)也可以