- 如何绑定 live 和 toggle 方法
无法直接使用,只能使用 $(yourhtml).is(":visiable") 来判断,如下是我的一个程序的一部分代码
//get comments for video $(".message_list").live("click", function(){ var vid = $(this).attr("ref"); var video_pane = $(this).parents(".video_pane"); if(video_pane.children(".message").length == 0) { $.get(GET_MESSAGES_URL, {id: vid}, function(data){ console.log(data); var options = { data: data, }; var html = Application.base.generate_message_pane(options); console.log(html); video_pane.append(html); },"json"); } else if($(video_pane.children(".message")[0]).is(':visible')){ $(video_pane.children(".message")[0]).hide("slow"); } else { $(video_pane.children(".message")[0]).show("slow"); } });
需要注意的是, 一定要将dom 转换成 jquery 对象
dom -> $(dom)