我目前正在使用prototype,例如,如果我想创建一个类或其他东西,我会这样做(在asp.net中使用它)
function MyTestClass()
{
this.MyHtmlDiv = $("myHtmlDiv");
this.MyButton = $("myButton");
this.init();
}
MyTestClass.prototype.init = function()
{
Event.Observe(...some code here ..);
Event.Observe(...more code...);
}你明白我的意思了。我喜欢它的组织方式,但我在其他帖子中读到过jquery更好。我想开始用它,但是..是否有可能创建这样的“类”,整齐?我通常对每个aspx页面都有一个单独的.js文件。如何使用JQuery创建这样的类?
任何指针,链接,想法或建议将不胜感激。当我在google上搜索它时,我看到了一些jquery函数,但还没有找到一个很好的模板,如果我要转到jquery,我可以遵循上面的方法来维护它。
发布于 2012-09-25 11:31:46
jQuery与你现在使用的风格没有冲突,你只需要改变你对jQuery选择器如何工作以及如何绑定事件处理程序等的想法。
function MyTestClass() {
// note jQuery's selector is different from Prototype
this.MyHtmlDiv = $("#myHtmlDiv");
this.MyButton = $("#myButton");
this.init();
}
MyTestClass.prototype.init = function() {
this.MyHtmlDiv.on('event_type', function() {
// some code
});
this.MyButton.on('event_type', function() {
// some code
});
}https://stackoverflow.com/questions/12575785
复制相似问题