Jquery问题可以帮助我解决我的jquery代码吗?

时间:2011-07-27 12:51:36

标签: jquery

我创建了一个名为“customize”的对象并添加了一些属性

var Customize = {
currentTab: (""||"accountdetails"),
openonload: false,
firstview: false,//false,
init: function() {
    //$('.customize-tabs li a').click(Customize.showTab);
    $('#toggle_customize').click(function () {
        alert('yes');
        if ( $(this).hasClass('active') ) {
            $('.cbm_control_closed').click(); // change this to Customize.close() when code is moved into that function
        } else {
            $(this).removeClass('inactive').addClass('active');
            Customize.open(Customize.currentTab);
            Customize.saveState();
        }
    });
    $('.cbm_control_closed').click(function() {
        $('#toggle_customize').removeClass('active').addClass('inactive');
        $('.customize-content').hide('fast');
        $('.customize-body').hide();
        $('.customize-pane').hide();
        $('#ui-tooltip-profile .button').click();
        // Hide save changes text
        Customize.Notifier.hide();
        // Get rid of heading pointer arrow
        $('.customize-tabs li').removeClass('active');
        Customize.saveState();
    });
    // set up Customize.Saver and field handlers
    Customize.initSavers();
    if (Customize.openonload) {
        //toggle customize modal
        $('#toggle_customize').removeClass('inactive').addClass('active');
        Customize.open(Customize.currentTab);
    }
    Customize.checkQueryActions();
},
open: function(which) {
    //legacy bug workaround
    //if (which != "services") { which = 'backgrounds'; }
    // show content
    $('.customize-body').show();
    // show nav
    $('.customize-content').show();
    // show tab
    Customize.showTab(which);
    Customize.showTooltips();
    UserProfile.offScreenFix();
},
close: function() {
    // TODO: move code from $('.cbm_control_closed').click to here
    // move $('.cbm_control_closed').click assignment to Customize.init
}};
$(document).ready(Customize.init);

现在我想调用$('#toggle_customize').click(function () {这个函数,所以我添加了这个HTML代码

<li id="toggle_customize"><a href="#"><span>Email Me</span></a></li>

但是当我点击“向我发送电子邮件”时,没有任何影响

但是当我把这个代码放在对象变量之外时,它就是

 $('#toggle_customize').click(function () {
    alert('yes');
    if ( $(this).hasClass('active') ) {
        $('.cbm_control_closed').click(); // change this to Customize.close() when code is moved into that function
    } else {
        $(this).removeClass('inactive').addClass('active');
        Customize.open(Customize.currentTab);
        Customize.saveState();
    }
});

任何人都可以帮助我理解这段代码。

感谢。

2 个答案:

答案 0 :(得分:0)

删除锚标记。它会在点击事件到达<li id="toggle_customize">

之前处理

像这样:<li id="toggle_customize"><span>Email Me</span></li>

如果您正在使用<a>,只需获取下划线或悬停样式,您只需要使用其他方式使用css ...

答案 1 :(得分:0)

$(document).ready(function(){

Customize.init();

});