原型>;JQuery转换

原型>;JQuery转换,jquery,ruby-on-rails,prototypejs,Jquery,Ruby On Rails,Prototypejs,我需要将一个脚本从Prototype转换为Jquery,但我不擅长Jquery 如果有人能做到这一点,我将非常感谢=) 以下是原型中的代码: // Place your application-specific JavaScript functions and classes here // This file is automatically included by javascript_include_tag :defaults replace_ids = function(s){ va

我需要将一个脚本从Prototype转换为Jquery,但我不擅长Jquery

如果有人能做到这一点,我将非常感谢=)

以下是原型中的代码:

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
replace_ids = function(s){
  var new_id = new Date().getTime();
  return s.replace(/NEW_RECORD/g, new_id);
}

var myrules = {
  '.remove': function(e){
    el = Event.findElement(e);
    target = el.href.replace(/.*#/, '.')
    el.up(target).hide();
    if(hidden_input = el.previous("input[type=hidden]")) hidden_input.value = '1'
  },
  '.add_nested_item': function(e){
    el = Event.findElement(e);
    template = eval(el.href.replace(/.*#/, ''))
    $(el.rel).insert({     
      bottom: replace_ids(template)
    });
  },
  '.add_nested_item_lvl2': function(e){
    el = Event.findElement(e);
    elements = el.rel.match(/(\w+)/g)
    parent = '.'+elements[0]
    child = '.'+elements[1]

    child_container = el.up(parent).down(child)    
    parent_object_id = el.up(parent).down('input').name.match(/.*\[(\d+)\]/)[1]

    template = eval(el.href.replace(/.*#/, ''))

    template = template.replace(/(attributes[_\]\[]+)\d+/g, "$1"+parent_object_id)

   // console.log(template)
    child_container.insert({     
      bottom: replace_ids(template)
     });
  }
};

Event.observe(window, 'load', function(){
  $('container').delegate('click', myrules);
});
谢谢你们

  • 谷歌“将原型转换为jquery”
  • 找一个有人在博客上写过如何做的页面
  • 阅读页面
  • 将学到的知识应用于手头的任务

  • 如果您遇到问题,请以特定问题的形式将其张贴在此处

    Hi Zettetic,很抱歉,我通常不会以这种方式寻求帮助。我对JQuery和Prototype知之甚少,我正在学习RubyonRails,我不得不进行这种转换。我无意滥用委员会成员的善意。我希望你能理解。Maikon没问题,很抱歉我的回答很尖刻。如果你表现出你已经先做了一些腿部工作,并且至少试着自己回答这个问题,你会得到更好的回答。我对第1点很认真——结果的第一页提供了一些关于如何将原型转换为jQuery的好信息。