怎么对一个事件调用两个函数的问题 http://www.scriptlover.com/pages/article.asp?ArticleID=219 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道该怎么搞呀把changeColor放到addOnClick事件里不行吗?友情顶一下啦 当然了,你在一个bothOperation中前后对tr对象的onclick事件进行了三次赋值.当然只有最后一次的赋值会有效了. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <script> var row = null; //动态获得单击行号并传给deleteRow();insertRow(); function addOnClick(){ for (var j = 0; j < document.getElementById("detail").rows.length; j++) { document.getElementById("detail").rows[j].onclick = showRowIndex; } } function showRowIndex(){ rowIIdex = this.sectionRowIndex; var trs = document.getElementById("detail").getElementsByTagName("tr"); for (var j = 0; j < trs.length; j++) { if (trs[j] == this) { this.style.backgroundColor = "green"; row = j; continue; } trs[j].style.backgroundColor = "#FFFFFF"; } } //删除行 function deleteRow(rowNum){ if (rowNum < 0) return; document.getElementById("detail").deleteRow(rowNum); } function bothOperation(){ addOnClick(); } </script> </head> <body oncontextmenu="event.returnValue=false;" onload="bothOperation();"> <input type="button" value="delete" onclick="deleteRow(row)"> <table border="1" id="detail"> <tr> <td> 111 </td> </tr> <tr id="detail"> <td> 111 </td> </tr> <tr id="detail"> <td> 111 </td> </tr> <tr id="detail"> <td> 111 </td> </tr> <tr id="detail"> <td> 111 </td> </tr> </table> </body> <script language="JavaScript"> </script></html> 后一个事件会覆盖前一个的这样试试function addOnClick() { for(var j=0;j <9;j++){ //document.getElementById("detail").rows[j].onclick = showRowIndex; } } function showRowIndex() { rowIIdex = this.sectionRowIndex; } //点击后行变色 function changeColor() { var trs = document.getElementById("detail").getElementsByTagName("tr"); addOnClick(); for(var i=0; i <trs.length; i++) { trs[i].onclick=function(){ showRowIndex.call(this); for(var j=0;j <trs.length;j++){ trs[j].style.backgroundColor = "#FFFFFF"; } this.style.backgroundColor = "green"; } } } //删除行 function deleteRow(rowNum) { detail.deleteRow(rowNum); } function bothOperation() { //addOnClick(); changeColor(); } <input tepy="button" onclick="bt()">function bt(){ bt01(); bt02();}function bt01(){}function bt02(){} 对,就是这样。调用a,a中调用b,c即可。 addOnClick写在changeColor里或者changeColor写在addOnClick里 js解析顺序,求科普 哪位老大给个下载javascript技术手册的链接? 第一次使用JS的面向对象,为什么后声明的类把先声明的类的属性覆盖了?? 正则表达式问题 如何替换clssname。谢谢! 在一个打开的模式窗口中新open一个窗口丢失SESSION 请问js怎样实现这个效果呢? 求0JS效果,两百分~~检测鼠标动作,全屏幕。 请问如何将"在javascript中alert输出",谢谢 如何取得浏览器地址栏中的字符串 google流量统计代码中javascript的执行次序问题 javascript如何获取上一页的地址
把changeColor放到addOnClick事件里不行吗?友情顶一下啦
当然只有最后一次的赋值会有效了.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script>
var row = null;
//动态获得单击行号并传给deleteRow();insertRow();
function addOnClick(){
for (var j = 0; j < document.getElementById("detail").rows.length; j++) {
document.getElementById("detail").rows[j].onclick = showRowIndex;
}
}
function showRowIndex(){
rowIIdex = this.sectionRowIndex;
var trs = document.getElementById("detail").getElementsByTagName("tr");
for (var j = 0; j < trs.length; j++) {
if (trs[j] == this) {
this.style.backgroundColor = "green";
row = j;
continue;
}
trs[j].style.backgroundColor = "#FFFFFF";
}
}
//删除行
function deleteRow(rowNum){
if (rowNum < 0)
return;
document.getElementById("detail").deleteRow(rowNum);
}
function bothOperation(){
addOnClick();
}
</script>
</head>
<body oncontextmenu="event.returnValue=false;" onload="bothOperation();">
<input type="button" value="delete" onclick="deleteRow(row)">
<table border="1" id="detail">
<tr>
<td>
111
</td>
</tr>
<tr id="detail">
<td>
111
</td>
</tr>
<tr id="detail">
<td>
111
</td>
</tr>
<tr id="detail">
<td>
111
</td>
</tr>
<tr id="detail">
<td>
111
</td>
</tr>
</table>
</body>
<script language="JavaScript">
</script>
</html>
这样试试
function addOnClick() {
for(var j=0;j <9;j++){
//document.getElementById("detail").rows[j].onclick = showRowIndex;
}
} function showRowIndex() {
rowIIdex = this.sectionRowIndex;
} //点击后行变色
function changeColor() {
var trs = document.getElementById("detail").getElementsByTagName("tr");
addOnClick();
for(var i=0; i <trs.length; i++) {
trs[i].onclick=function(){
showRowIndex.call(this);
for(var j=0;j <trs.length;j++){
trs[j].style.backgroundColor = "#FFFFFF";
}
this.style.backgroundColor = "green";
}
}
} //删除行
function deleteRow(rowNum) {
detail.deleteRow(rowNum);
} function bothOperation() {
//addOnClick();
changeColor();
}
function bt(){
bt01();
bt02();
}
function bt01(){}
function bt02(){}
对,就是这样。调用a,a中调用b,c即可。