Zan*_*der 5 javascript dom javascript-events ender
我刚开始尝试使用微型库而不是使用jQuery,我想将qwery与bean一起使用.如果我设置bean.setSelectorEngine(qwery);为什么以下不起作用?
bean.on('.masthead', 'click', function () {
console.log('click fired');
});
Run Code Online (Sandbox Code Playgroud)
我也使用bonzo作为DOM实用程序,所以我将它设置为使用美元和qwery,这样我就可以像jQuery一样选择元素:例如$('.masthead').
function $(selector) {
return bonzo(qwery(selector));
}
Run Code Online (Sandbox Code Playgroud)
这也行不通.我是否应该无法使用以下bean?
bean.on($('.masthead'), 'click', function () {
console.log('click fired');
});
Run Code Online (Sandbox Code Playgroud)
也许我错过了bean文档中的重要内容..我需要做些什么来解决这个问题?
此外,我试图尽量避免使用Ender,我试图将我的外部库保持在最低限度.
是的,您可以在没有Ender的情况下将所有这些库一起使用.但是你必须自己连接这些库之间的所有连接.
这应该让你开始:
// make Bean and Bonzo use Qwery
// as their internal selector engine
bean.setSelectorEngine(qwery);
bonzo.setQueryEngine(qwery);
// to use $ instead of bonzo
function $(selector, root) {
return bonzo(qwery(selector, root));
};
// $() will return a bonzo object
// so if you want to be able to use
// bean's methods on the bonzo object
// like $().on()
// you are going to have to extend bonzo
bonzo.aug({
on: function (eventName, callback) {
return this.each(function (elem) {
return bean.on(elem, eventName, callback);
});
},
// do the same for bean's other methods (fire, off, etc)
});
// now you should be able to do this:
$('.masthead').on('click', function () {
console.log('click fired');
});
Run Code Online (Sandbox Code Playgroud)
希望有所帮助!:)
| 归档时间: |
|
| 查看次数: |
859 次 |
| 最近记录: |