简体   繁体   English

空主体的JS(jQuery)函数

[英]JS (jQuery) function with empty body

I have a function in the code that wasn't written by me. 我的代码中没有我编写的函数。

$("*").not("a, li, ul").click('click', function(){})

This function replaces event listeners on empty string or what? 此函数替换空字符串上的事件侦听器或什么? What is the purpose of making functions with empty body. 用空的身体做功能的目的是什么。 Is any other way to write things clear? 还有其他写东西的清晰方法吗?

It does nothing. 它什么也没做。 It doesn't add something, nor does it remove something. 它不会添加任何东西,也不会删除任何东西。 It's just wasted internet traffic bytes because more data has to be downloaded by the client. 这只是浪费互联网流量字节,因为客户端必须下载更多数据。 See below, it still executes all: 如下所示,它仍然执行所有操作:

 $('#a').click(function() {alert("foo")}); $('#a').click(function() {}); $('#a').click(function() {}); $('#a').click(function() {}); $('#a').click(function() {}); $('#a').click(function() {alert("bar")}) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="a"> a </div> 

There's no purpose of adding empty listeners what so ever. 如此添加空听众是没有目的的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM