我正在将文件从原型(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/