jQuery and “Organized Code”

后端 未结 8 1776
星月不相逢
星月不相逢 2020-12-12 11:52

I\'ve been struggling lately with understanding the best way to organize jQuery code. I asked another question earlier and I don\'t think I was specific enough (found in thi

相关标签:
8条回答
  • 2020-12-12 12:25

    Use http://coffeescript.com/ ;)

    $ ->
      container = $ '#inputContainer'
      for i in [0...5]
        $('<input/>').change ->
          $.ajax success: (data) ->
            for w in container.children()
              $(w).unbind().change ->
                alert 'duh'
    
    0 讨论(0)
  • 2020-12-12 12:33

    Just want to add to what was mentioned previously that this:

    $.each(container.children(), function(j,w) {
        $(w).unbind().change(function() { ... });
    });
    

    can be optimized to:

    container.children().unbind().change(function() { ... });
    

    It's all about chaining, a great way to simplify your code.

    0 讨论(0)
提交回复
热议问题