jquery通过live绑定toggle事件

$("a[name=reply]").live("click",function(){
$(this).toggle(
function () {
var $comments = $('#microBlogReplyContainer_' + $(this).attr("value"));
$comments.load($comments.attr("value"));
$("#ListComments_" + $(this).attr("value")).show();
var count = $(this).text().replace(/[^0-9]/ig, "");
if (!count) count = 0;
$(this).text('收起评论(' + count + ')');
},
function () {
var $comments = $('#microBlogReplyContainer_' + $(this).attr("value"));
$("#ListComments_" + $(this).attr("value")).hide();
var count = $(this).text().replace(/[^0-9]/ig, "");
if (!count) count = 0;
$(this).text('评论(' + count + ')');
}
).trigger('click');
});
直接拿示例代码:
$('.comBtn').live("click",function(){
 $(this).toggle(function(){ $(this).parent().parent().next('.msd_tipbox').show(); }, 
 function(){ $(this).parent().parent().next('.msd_tipbox').hide(); }).trigger('click');; } );

说明:通过click事件绑定.再用 trigger('click')触发.防止点击第一次无效

上一篇:linux下nginx的安装和配置


下一篇:带额外toggle()功能的jquery库