有谁知道任何基于人员的 JavaScript/jQuery 源代码审计网站/论坛/社区?

发布于 2024-09-30 21:00:47 字数 523 浏览 2 评论 0原文

您好,我正在为我的应用程序编写 jQuery 代码,但遇到了一些问题(例如函数调用一次,运行三次)。 我必须知道是否存在任何人们审核源代码并评论我的错误的网站。

我的大部分代码都是这样的:

$('a.openBox').click(function(){
  //do something
  $('.box').show();
  $('a.openModal','.box').click(function(){
     $.openModal(some, parameters)
  });
});

$.openModal = function(foo,bar){
    //do something
    $('a.close').click(function(){
        $('#modal').hide();
     });
    $('input.text').click(function(){
        $.anotherFunction();
     });
});

我是否在做一些明显错误的事情?

Hello I'm writing a jQuery code for my application and got some issues (like function called once, running three times).
I must know if exist any site that people audit source code and comment my mistakes..

most of my code is like this i/e:

$('a.openBox').click(function(){
  //do something
  $('.box').show();
  $('a.openModal','.box').click(function(){
     $.openModal(some, parameters)
  });
});

$.openModal = function(foo,bar){
    //do something
    $('a.close').click(function(){
        $('#modal').hide();
     });
    $('input.text').click(function(){
        $.anotherFunction();
     });
});

does am I doing something obviously wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左耳近心 2024-10-07 21:00:47

我不知道有任何类似的源代码审计——当然不是免费的!不过,这个网站对于特定问题来说非常好......

在这种情况下,问题是您不断绑定越来越多的事件。例如,使用以下代码:

$('a.openBox').click(function(){
  //do something
  $('.box').show();
  $('a.openModal','.box').click(function(){
     $.openModal(some, parameters)
  });
});

此代码表示“每当用户单击 a.openbox 元素时,显示所有 .box 元素并绑定新的单击所有 .box a.openModal 元素的处理程序”。这意味着每次单击 a.openbox 时,您都会向 .box a.openModal 添加另一个处理程序。我不敢相信这就是你想做的事!

如果不了解上下文以及您想要发生的情况,就很难确定正确的代码应该是什么。首先,我对您的建议是阅读 Javascript 事件和事件处理程序,特别是它们是在 jQuery 中实现的。

I'm not aware of any source code audit like that -- certainly not for free! This website is pretty good for specific problems though...

In this case, the problem is that you are continually binding more and more events. For instance, with the following code:

$('a.openBox').click(function(){
  //do something
  $('.box').show();
  $('a.openModal','.box').click(function(){
     $.openModal(some, parameters)
  });
});

This code says "whenever the user clicks on an a.openbox element, show all .box elements and bind a new click handler to all .box a.openModal elements". This means that you will add another handler to .box a.openModal every time you click on a.openbox. I can't believe this is what you want to do!

It is difficult to work out what the correct code should be without knowing the context and exactly what you want to happen. My advice for you in the first instance would be to do some reading up on Javascript events and event handlers, particularly as they are implemented in jQuery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文