如何在没有 setTimeout 的情况下加载值?
看下面的例子:
<select id="connection" onchange="load_databases_of_this_connection();"></select>
<select id="database" onchange="load_tables_of_this_database();"></select>
<select id="table" onchange="load_columns_of_this_table();"></select>
<input id="fieldcode" type="text"/>
<input id="fieldcolor" type="text"/>
<script type="text/javascript" language="javascript">
$('#connection').change();
setTimeout("x()",2000 ); // select database and load tables
function x() {
$('#database').val( 'main_database' );
$('#database').change();
setTimeout("t()",2000 ); // select table and load columns
}
function t() {
$('#table').val( 'payments' );
$('#table').change();
setTimeout("a()",2000 ); // select columns
}
function a() {
$('#fieldcode').val( 'code' );
$('#fieldcolor').val( 'status' );
}
</script>
这段代码可以工作,但我不喜欢它。我想要做的是随后加载值,当“更改事件”结束(成功或完成)时,然后调用下一个,例如,如果我在没有 setTimeout 的情况下执行以下示例,则这不起作用:
<script type="text/javascript" language="javascript">
$('#connection').change();
$('#database').val( 'main_database' );
$('#database').change();
$('#table').val( 'payments' );
$('#table').change();
$('#fieldcode').val( 'code' );
$('#fieldcolor').val( 'status' );
</script>
I'm trying to do it with ajaxComplete but I get an infinite cycle, dure to each ajax call ends the ajaxComplete is called ... :$('#database').ajaxComplete( function (e) {
$('#table').val( 'payments' );
$('#table').change();
} );
请帮忙!
Look the following example:
<select id="connection" onchange="load_databases_of_this_connection();"></select>
<select id="database" onchange="load_tables_of_this_database();"></select>
<select id="table" onchange="load_columns_of_this_table();"></select>
<input id="fieldcode" type="text"/>
<input id="fieldcolor" type="text"/>
<script type="text/javascript" language="javascript">
$('#connection').change();
setTimeout("x()",2000 ); // select database and load tables
function x() {
$('#database').val( 'main_database' );
$('#database').change();
setTimeout("t()",2000 ); // select table and load columns
}
function t() {
$('#table').val( 'payments' );
$('#table').change();
setTimeout("a()",2000 ); // select columns
}
function a() {
$('#fieldcode').val( 'code' );
$('#fieldcolor').val( 'status' );
}
</script>
This code works, but I don't like it. What I want to do is to load the values subsequently, when the "change event" ends (succes or completed) then call the next, for example if I do the following example without setTimeout this not works:
<script type="text/javascript" language="javascript">
$('#connection').change();
$('#database').val( 'main_database' );
$('#database').change();
$('#table').val( 'payments' );
$('#table').change();
$('#fieldcode').val( 'code' );
$('#fieldcolor').val( 'status' );
</script>
I'm trying to do it with ajaxComplete but I get an infinite cycle, dure to each ajax call ends the ajaxComplete is called ... :
$('#database').ajaxComplete( function (e) {
$('#table').val( 'payments' );
$('#table').change();
} );
PLEASE HELP!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很容易解决...
I solved easy...
我假设您的代码比您看到的要多,如果是这样,这应该可以解决问题:
I'm assuming there is more to your code than meets the eye, if so this should do the trick: