【问题标题】:jQuery code, how I can do easier to readjQuery 代码,我怎样才能更容易阅读
【发布时间】:2018-04-21 11:41:41
【问题描述】:

我想尝试让我的代码更易于阅读,我正在寻找类似的解决方案,在 Visual Basic 中:

 With $('.class or sector') {
    $(this).removeClass('some-class');
    $(this).addClass('some-other-class');
 } End With

我试过了,但它不起作用:

$('.class or sector') = function() {
    $('.class or sector inside > *', this).addClass('some-class');
}

.container.footer-finale 内部的一个类 也许任何人都可以帮助我

【问题讨论】:

  • 你想做什么?你的 HTML 代码在哪里?
  • 我想尝试让我的代码更易于阅读... html 代码并不重要。我不想总是写... $('.footer-finale .container')... $('.footer-finale span > a')... 或类似的东西

标签: jquery code-readability


【解决方案1】:

jQuery 使用流畅的界面,因此您可以链接您的调用。

$('.class')
    .removeClass('some-class')
    .addClass('some-other-class');

你也可以分配一个变量:

var item = $('.class');
item.removeClass('some-class');
item.addClass('some-other-class');

【讨论】:

  • 谢谢...这就是我要找的
猜你喜欢
  • 2019-12-16
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多