怀疑事件处理程序的执行顺序! ! [英] Doubt in order of event handler excecution ! !

查看:74
本文介绍了怀疑事件处理程序的执行顺序! !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个不同的js文件中有两个点击事件处理程序。

在file1中说:

$('。test')。live('click', function(){

// action 1

}



file 2:

$('。test')。live('click',function(){

// action 2

}



我尝试了什么:



将首先执行。?我的假设是,它将基于执行加载js文件的顺序。但我不确定。任何人都可以清楚我的疑问吗?

解决方案

('。test')。live('click ',function(){

//行动1

}



档案2:


('。test')。live('click',function(){

// action 2

} < br $> b $ b

我尝试了什么:



将首先执行。?我的假设是,它将根据加载的js文件的顺序执行。但我是n确定。任何人都可以清楚我的怀疑吗?


首先执行第一个文件引用。



测试如下



<!DOCTYPE html> 
< html>
< head>
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js>
< / script>
< script src =Scripts / JavaScript1.js>< / script>
< script src =Scripts / JavaScript2.js>< / script>
< / head>

< body>
< button class =test>点击测试< / button>
< / body>
< / html>

< / html>





文件1

 

i am having two click event handlers in two different js files.
say in file1:
$('.test').live('click',function() {
//action 1
}

file 2 :
$('.test').live('click',function() {
//action 2
}

What I have tried:

which will execute first .? My assumption is , it will be executed based on the order of js file loaded. but i am not sure . can any one clear my doubt ??

解决方案

('.test').live('click',function() {
//action 1
}

file 2 :


('.test').live('click',function() {
//action 2
}

What I have tried:

which will execute first .? My assumption is , it will be executed based on the order of js file loaded. but i am not sure . can any one clear my doubt ??


First File reference will be executed first.

tested as below

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">
    </script>
    <script src="Scripts/JavaScript1.js"></script>
    <script src="Scripts/JavaScript2.js"></script> 
</head>
 
<body >
   <button class="test"> click to test </button>  
</body>
</html>
 
</html> 



File 1


这篇关于怀疑事件处理程序的执行顺序! !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆