javascript - 将 js 文件从原型(prototype)迁移到 jQuery 不起作用

标签 javascript jquery prototype

我正在将文件从原型(prototype)迁移到 jQuery。

原型(prototype):

function hideEditableMarkers() {
   $$('.edit_marker').each(function(el) {
  el.hide();
});
   $$('.show_marker').each(function(el) {
    el.show();
    });
}

Event.observe(window, 'load', hideEditableMarkers);

jQuery:

function hideEditableMarkers() {
  jQuery('.edit_marker').each(function(el){
    el.hide();
    });

  jQuery('.show_marker').each(function(el){
    el.show();
    }); 
}

jQuery(document).ready(hideEditableMarkers());

我不知道为什么它不起作用。

最佳答案

each 回调函数的第一个参数是元素的索引,而不是对其的引用

这是 jquery 代码

function hideEditableMarkers() {
  $('.edit_marker').each(function(idx,el){
    $(el).hide(); // You may use 'this' variable in here as it points to the current element as well
    });

  $('.show_marker').each(function(idx,el){
     $(el).show();
    }); 
}

关于javascript - 将 js 文件从原型(prototype)迁移到 jQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19489195/

相关文章:

javascript - xxxx.xxx.xxx 的正则表达式

javascript - CSS3 的浏览器兼容性问题

javascript - 逆对象元素顺序

javascript - array.prototype.slice.call 中的原型(prototype)有什么用

创建 Iframe 的 Javascript

javascript - 在node.js中返回数据

jQuery ui 列表排序

javascript - 在 each() 的 div 中访问输入的值

javascript - 添加到 Object.prototype 的方法重复无限次

javascript - Object.create vs new 在原型(prototype)继承方面