我刚看过这个教程: http://rmurphey.com/blog/2009/10/15/using-objects-to-organize-your-code/
我试图以对象文字格式设置一个函数(通用且可重用)。但我似乎无法让它运作?有人看到我的代码有问题吗?
// Generic Email Signup via Bronto
var emailSignup = {
'config' : {
// Configurable Options
'container' : $('#email-signup'),
'emailButton' : $('#email-submit'),
'emailErrorContainer' : $('#email-error'),
'emailInput' : $('#mail-signup-input'),
'brontoDirectAddURL' : 'http://app.bronto.com/public/?q=direct_add&fn=Public_DirectAddForm&id=cczmcguxestyqabxqmbvwznavplrbom&email=',
'brontoListID' : '0bbc03ec000000000000000000000003287b',
// configurable function for getting
// a URL for loading item content
},
'init' : function(config) {
// stays the same
// provide for custom configuration via init()
if (config && typeof(config) == 'object') {
$.extend(emailSignup.config, config);
}
// create and/or cache some DOM elements
// we'll want to use throughout the code
emailSignup.$container = emailSignup.config.container;
emailSignup.$errorContainer = emailSignup.config.emailErrorContainer;
emailSignup.$button = emailSignup.config.emailButton;
emailSignup.$input = emailSignup.config.emailInput;
// Add email track to drop image pixel into for submission
emailSignup.$errorContainer.append('<div class="track"></div>');
// Call getEmail
emailSignup.getEmail(emailSignup.$button);
// make a note that the initialization
// is complete; we don't strictly need this
// for this iteration, but it can come in handy
emailSignup.initialized = true;
},
'getEmail' : function($button) {
// click event
emailSignup.$button.click(function(){
console.log('test click');
});
},
'validateEmail' : function() {
var $emailRegEx = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var $emailVal = emailSignup.$input.val();
},
'submitEmail' : function($emailVal) {
$(".track").html('<img src="http://app.bronto.com/public/?q=direct_add&fn=Public_DirectAddForm&id=cczmcguxestyqabxqmbvwznavplrbom&email=' + email + '&list1=0bbc03ec000000000000000000000003287b" width="0" height="0" border="0" alt=""/>');
},
};
$(document).ready(function() {
emailSignup.init({ 'emailInput' : '#email-input' });
});
答案 0 :(得分:0)
没关系,似乎工作正常。