onclick事件中JS函数的执行顺序

wabania 2008-05-29 04:20:43
onclick事件如下:
<input type ='button' onclick=a();b();c();/>

a()删除table中某一行,b(),c()执行整个document的input域的计算操作。当onclick操作只有a()的时候,删除一行很快,但加上b(),c()后,删除一行速度很慢了。b(),c()计算速度慢属于正常。
但我觉得应该是先执行完a()后再执行b,c,这时候行已经删除了,无论b,c怎么慢都不会影响到行的删除。好像是先执行完b,c再执行a一样。怎么回事呢?

附:
行的结构大概如下:
<tr><td><input type='hidden' name='a'/>
<input type='hidden' name='b'>
<input type='hidden' name='c'>
<input type='hidden' name='d'>
<input type='hidden' name='e'>
<input type='hidden' name='f'>
</td>
<td><input type='hidden' name='g'></td>
<td><input type='hidden' name='h'></td>
<td><input type='hidden' name='1'></td>
<td><input type='hidden' name='2'></td>
<td><input type='hidden' name='3'></td>
</tr>
...全文
863 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
浴火_凤凰 2008-06-09
  • 打赏
  • 举报
回复
不懂啊!
wabania 2008-05-30
  • 打赏
  • 举报
回复
怎么没人理了呢
wabania 2008-05-29
  • 打赏
  • 举报
回复
function deletePlanItem(obj,splitNumber,groupTypeCode) {
var row = obj.parentElement.parentElement;
var table = row.parentElement;
var rowIdx = row.rowIndex;
if(splitNumber != 0){
if(row.cells[1].children[2].value == 0){
for(var idx = 0; idx < splitNumber; idx++){
table.deleteRow(rowIdx);
}
}else{
row.cells[1].children[2].value = row.cells[1].children[2].value*(-1);
row.style.display = "none";
for(var idx = 1; idx < splitNumber; idx++){
table.deleteRow(row.nextSibling.rowIndex);
}
}
eval("gbl_"+groupTypeCode+"--");
}else{
if(row.cells[1].children[2].value == 0){
table.deleteRow(rowIdx);
}else{
row.style.display = "none";
row.cells[1].children[2].value = row.cells[1].children[2].value*(-1);
}
}
refreshRowNum(table,splitNumber,groupTypeCode);
}
function refreshRowNum(oTable,splitNumber,groupTypeCode) {
var j = 1;
if(splitNumber != 0){
for (var i = 1; i < oTable.rows.length-1; i++) {
var oRow = oTable.rows[i];
if(oRow.style.display != "none" && oRow.cells[0].rowSpan == splitNumber){
var tdHtml = oRow.cells[1].innerHTML;
var sub_tdHtml = tdHtml.substr(0,tdHtml.lastIndexOf('>')+1);
oRow.cells[1].innerHTML = sub_tdHtml + j;
j++;
}
}
eval("gbl_"+groupTypeCode+"=j");
}else{
for (var i = 1; i < oTable.rows.length-1; i++) {
var oRow = oTable.rows[i];
if(oRow.style.display != "none"){
var tdHtml = oRow.cells[1].innerHTML;
var sub_tdHtml = tdHtml.substr(0,tdHtml.lastIndexOf('>')+1);
oRow.cells[1].innerHTML = sub_tdHtml + j;
j++;
}
}
}
}

只发一段吧,这是函数a()的内容
wabania 2008-05-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 pippe 的回复:]
在a方法的最后调用用
setTimeout("b()", 100)
setTimeout("c()", 100)
<input type ='button' onclick="a()"/>

或者将setTimeout写在onclick里也可以
[/Quote]

试了这个,也没用

页面加载后的代码1446行,我不敢往上放
pippe 2008-05-29
  • 打赏
  • 举报
回复
用setTimeout延迟执行就可以让用户感觉不到了
wabania 2008-05-29
  • 打赏
  • 举报
回复
我的代码还是别发了,发完我还要解释很久
wabania 2008-05-29
  • 打赏
  • 举报
回复
我想将onclick事件变成onchange事件来执行a,b,c .
test(){
a();
b();
c();
}
<input name='input1' type='text' onchange='test()'/>
因为b,c执行的时间比较长,能不能执行完a后就让让input1失去焦点,可以让用户感觉不到b,c的执行
wabania 2008-05-29
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 btbtd 的回复:]
<input type ='button' onclick="a();b();c();"/>
<table>
<tr> <td> <input type='hidden' name='a'/>
<input type='hidden' name='b'>
<input type='hidden' name='c'>
<input type='hidden' name='d'>
<input type='hidden' name='e'>
<input type='hidden' name='f'>
</td>
<td> <input type='hidden' name='g'> </td>
<td> <input type='hidden' …
[/Quote]

这是干嘛用的呢
lfywy 2008-05-29
  • 打赏
  • 举报
回复
当然是先从函数到函数,然后从上到下的顺序执行!
btbtd 2008-05-29
  • 打赏
  • 举报
回复
<input type ='button' onclick="a();b();c();"/>
<table>
<tr> <td> <input type='hidden' name='a'/>
<input type='hidden' name='b'>
<input type='hidden' name='c'>
<input type='hidden' name='d'>
<input type='hidden' name='e'>
<input type='hidden' name='f'>
</td>
<td> <input type='hidden' name='g'> </td>
<td> <input type='hidden' name='h'> </td>
<td> <input type='hidden' name='1'> </td>
<td> <input type='hidden' name='2'> </td>
<td> <input type='hidden' name='3'> </td>
</tr>
</table>
<style type="text/css">
/* <![CDATA[ */

/* ]]> */
</style>

<script type="text/javascript">
/*<![CDATA[*/
function a(){alert('a')};
function b(){alert('b')};
function c(){alert('c')};
/*]]>*/
</script>
wdbjsh 2008-05-29
  • 打赏
  • 举报
回复
wabania 2008-05-29
  • 打赏
  • 举报
回复
代码太长了,1000多行啊。需要发吗
  • 打赏
  • 举报
回复
楼上正解
jayflee 2008-05-29
  • 打赏
  • 举报
回复
这样?

function a(){

//你的代码
b();
c();

}
hztgcl1986 2008-05-29
  • 打赏
  • 举报
回复
把a(),b(),c()代码贴出来
pippe 2008-05-29
  • 打赏
  • 举报
回复
在a方法的最后调用用
setTimeout("b()", 100)
setTimeout("c()", 100)
<input type ='button' onclick="a()"/>

或者将setTimeout写在onclick里也可以
s_liangchao1s 2008-05-29
  • 打赏
  • 举报
回复
把代码拿过来瞧瞧
wdbjsh 2008-05-29
  • 打赏
  • 举报
回复
挺晕滴~~~~
lawrendc 2008-05-29
  • 打赏
  • 举报
回复
没遇到过

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧