【问题标题】:How to convert this code to coffeescript如何将此代码转换为咖啡脚本
【发布时间】:2015-04-10 22:18:26
【问题描述】:

我有以下代码:

function toggleChecked(status) {
  $(".checkbox").each( function() {
    $(this).attr("checked",status);
  })
}

我不知道如何更改其中的 each 子句和匿名函数。

【问题讨论】:

    标签: jquery coffeescript


    【解决方案1】:
    toggleChecked = (status) ->
      $(".checkbox").each ->
        $(this).attr "checked", status
    

    请注意,您可以使用Js2coffee 将 JavaScript 转换为 CoffeeScript。

    【讨论】:

      猜你喜欢
      • 2013-09-03
      • 2012-10-24
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      相关资源
      最近更新 更多