从jQuery到Prototype

时间:2009-07-08 12:32:03

标签: jquery function prototypejs

请帮助用Prototype替换这些jQuery函数:

$("button,input,label,select,textarea").bind('mouseover mouseout',
               function(){$(this).toggleClass('hover')});
$("button,input,select,textarea").bind('focus blur',
               function(){$(this).toggleClass('focus')});

1 个答案:

答案 0 :(得分:4)

var toggleClass = function(name) { $(this).toggleClassName(name) }
Event.observe($$("button,input,label,select,textarea"), 'mouseover', toggleClass.bind(this, 'hover'));
Event.observe($$("button,input,label,select,textarea"), 'mouseout', toggleClass.bind(this, 'hover'));
Event.observe($$("button,input,select,textarea"), 'focus', toggleClass.bind(this, 'focus'));
Event.observe($$("button,input,select,textarea"), 'blur', toggleClass.bind(this, 'focus'));