如何使用同一个类两次执行两个事件?jquery

如何使用同一个类两次执行两个事件?jquery,jquery,Jquery,我正在尝试使用jquery中的同一个类执行两个事件。。。让它工作起来真是太辛苦了 我需要类的id,所以我不能用它来代替。。。一定有办法做到这一点 $(document).ready(function() { $("a.comm_link").anchorAnimate() }); function open_Comm(id) { $('.comm_link').live("click",function() { var id = $(this).attr("id"); $("a.commscr

我正在尝试使用jquery中的同一个类执行两个事件。。。让它工作起来真是太辛苦了

我需要类的id,所以我不能用它来代替。。。一定有办法做到这一点

$(document).ready(function() {
$("a.comm_link").anchorAnimate()
});

function open_Comm(id) {
$('.comm_link').live("click",function() {
var id = $(this).attr("id");
$("a.commscroll"+id).anchorAnimate();
$("#comment_div"+id).css('display','');
$("#commval"+id+":input:visible:enabled:first").focus();
$("#commval"+id).val("");
$("textarea#commval"+id).blur(function() {
if($("#commval"+id).val() == "") {
$("#comment_div"+id).css('display','none');
}
});
return false;
});
}

/*******
*** Anchor Slider by Cedric Dugas   ***
*** Http://www.position-absolute.com ***
Never have an anchor jumping your content, slide it.
Don't forget to put an id to your anchor !
You can use and modify this script for any project you want, but please leave this comment as credit.
*****/
jQuery.fn.anchorAnimate = function(settings) {
settings = jQuery.extend({
speed : 1200
}, settings);   
return this.each(function(){
var caller = this
$(caller).click(function (event) {  
event.preventDefault()
var locationHref = window.location.href
var elementClick = $(caller).attr("href")
var destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
window.location.hash = elementClick
});
return false;
})
})
}
以下是html:

<div class='comment' id='comment".$eid."' style='float:right;padding-right:3px;visibility:hidden;'>
<a href='#commscroll".$eid."' onclick=\"javascript:open_Comm('".$eid."');\" class='comm_link' id='".$eid."'>
<img src='http://mydomain.com/images/comment.gif' border='0' style='overflow:hidden;vertical-align:middle;text-decoration:none;border:0px;outline:none;'>Comment</a>
</div>
<div class='clear'></div>

好的,您不能在任一单击事件中使用
返回:false
,因为这将取消默认的,并停止事件冒泡

live('click')…
anchorAnimate
click
事件中,仅使用
e.preventDefault

$('.comm_link').live("click",function(e) {

    ... all your code ...

    // DON'T use return false; Remove it
    e.preventDefault();
});
以及:


好的,您不能在任一单击事件中使用
return:false
,因为这将取消默认的,并停止事件冒泡

live('click')…
anchorAnimate
click
事件中,仅使用
e.preventDefault

$('.comm_link').live("click",function(e) {

    ... all your code ...

    // DON'T use return false; Remove it
    e.preventDefault();
});
以及:


@布兰登:这是你的全部片段(重新格式化)调用在正确的位置,并删除return false:谢谢doug…我粘贴了重新格式化的代码,在单击“注释”后,滚动动画似乎有2秒的延迟?你知道可能是什么原因吗?实际上它根本没有动画,它只是跳跃???以前从未在两个单独的事件中使用同一个类!:-)@布兰登:这是你的全部片段(重新格式化)调用在正确的位置,并删除return false:谢谢doug…我粘贴了重新格式化的代码,在单击“注释”后,滚动动画似乎有2秒的延迟?你知道可能是什么原因吗?实际上它根本没有动画,它只是跳跃???以前从未在两个单独的事件中使用同一个类!:-)