【问题标题】:Prototype > JQuery Conversion原型 > JQuery 转换
【发布时间】:2010-10-01 03:18:12
【问题描述】:

我需要将一个脚本从 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 ruby-on-rails prototypejs


    【解决方案1】:
    1. Google“将原型转换为 jquery”
    2. 查找某人在博客中介绍如何操作的页面
    3. 阅读页面
    4. 将学到的知识应用到手头的任务中

    如果您遇到问题,请以具体问题的形式在此处发布

    【讨论】:

    • 嗨 zetetic,很抱歉这个问题,我通常不会以这种方式寻求帮助。我真的对 JQuery 和 Prototype 知之甚少,我正在学习 Ruby on Rails,我必须进行这种转换。我无意滥用 stackoverflow 成员的善意。我希望你明白。麦孔
    • 没问题,很抱歉这个尖刻的回答。如果你表明你已经先做了一些跑腿工作,并且至少尝试自己回答问题,你会得到更好的回答。我对第 1 点很认真——结果的第一页提供了一些关于如何将 Prototype 转换为 jQuery 的好信息。
    猜你喜欢
    • 2010-10-09
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多