开发者

Working with a clone() menu on jQuery to load a menu from PHP

Based in this ex. How to use toggle event with live? I'm trying to get working this code on a clone() menu which stays always on top as in this ex. ht开发者_JAVA技巧tp://jsfiddle.net/fj8wM/181/ the original worked fine, but the cloned one does not work as well.

$("#showmenu").live('click', function () {
    var toggled = $('#menudiv').data('toggled');
        $('#menudiv').data('toggled', !toggled);
            if (!toggled) {
              setCookie('show_menu','1','1');
              $('#showmenu').html('Hide menu');
              $('#menudiv').slideDown();
              $('#menudiv div').load('menu.php');
    } else {
              $('#menudiv').slideUp();
              $('#menudiv').remove('#menudiv div');
              setCookie('show_menu','','');
              $('#showmenu').html('Show menu');   
    }
}); 
      
    var cmenu = getCookie('show_menu');
        if(cmenu){
        $('#showmenu').html('Hide menu');
        $('#menudiv').load('menu.php');
        $('#menudiv').show();
        }


Are you referring to alert not triggering when you click the link? Just replace this:

$('#login').click(function(){
    alert('hi');
});

with this:

$('#login').live('click', function(){
    alert('hi');
});

UPDATE: this is more of a hack, it can certainly be tidied up but I think it does what you wanted. I had to change the html slightly as well as js: http://jsfiddle.net/fDgke/3/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜