为了让我的Javascript变得不那么引人注目,我使用了onLoads来给Javascript s等等添加功能。在Dojo中,这看起来类似于:
var coolInput = dojo.byId('cool_input');
if(coolInput) {
dojo.addOnLoad(function() {
coolInput.onkeyup = function() { ... };
});
}或者,大致等同地:
dojo.addOnLoad(function() {
dojo.forEach(dojo.query('#cool_input'), function(elt) {
elt.onkeyup = function() { ... };
});
});有没有人写了一个Ruby的andand实现,这样我就可以做下面的事情了?
dojo.addOnLoad(function() {
// the input's onkeyup is set iff the input exists
dojo.byId('cool_input').andand().onkeyup = function() { ... };
});或
dojo.byId('cool_input').andand(function(elt) {
// this function gets called with elt = the input iff it exists
dojo.addOnLoad(function() {
elt.onkeyup = function() { ... };
});
});发布于 2009-04-14 21:25:55
你想要dojo.behavior。
dojo.behavior.add({
'#cool_input': {
onKeyUp: function(evt) { ... }
}
});https://stackoverflow.com/questions/422355
复制相似问题