Jquery点击事件不点火,但是第二次点击,为什么? [英] Jquery Click Event Not Firing On First Click, but does on second click, why?

查看:117
本文介绍了Jquery点击事件不点火,但是第二次点击,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery代码,其中

I've got a jquery code, which

$("a.reply").click(function() {
//code
});

当我第一次单击与.reply类的链接时,没有任何反应。第二次点击,点击功能内的代码工作。

When I click the link with .reply class the first time, nothing happens. The second time I click, the code inside the click function works.

使用mysql数据库中的php将链接插入页面。所以没有动态插入。

The link is being inserted on the page using php from a mysql database. so it's not being inserted dynamically.

为什么会发生这种情况?任何解决方案?

Why is this happening? Any solution?

BadASS代码

$(function(){
//TextArea Max Width
var textmaxwidth = $('#wrapper').css('width');
//Initialize Focus ids To Different Initially
var oldcommentid = -1;
var newcommentid = -2;
//End Of initialization

$("a.reply").click(function() {
        newcommentid = $(this).attr('id');
        if (newcommentid == oldcommentid)
        {
        oldcommentid=newcommentid;
        $("#comment_body").focus();
        }
        else
        {
        $('#comment_form').fadeOut(0, function(){$(this).remove()});
        var commetformcode = $('<form id="comment_form" action="post_comment.php" method="post"><textarea name="comment_body" id="comment_body" class="added_comment_body" rows="2"></textarea> <input type="hidden" name="parent_id" id="parent_id" value="0"/> <div id="submit_button"> <input type="submit" value="Share"/><input type="button" id="cancelbutton" value="Cancel"/></div></form>');
        commetformcode.hide().insertAfter($(this)).fadeIn(300);
        //
        var id = $(this).attr("id");
        $("#parent_id").attr("value", id);
        oldcommentid=newcommentid;
        //dynamicformcreation function
        dynarun();
        //
        }



        return false;
    });

        dynarun();

        function dynarun()
        {
        //Form Re-Run Functions
        $('#comment_body').elastic();
        texthover();
        $("#comment_form input, select, button").uniform();
        textareasizer();
        $("#comment_body").focus();
        $("abbr.timestamp").timeago();
        return false;
        }

        //TextArea Resizer Function
        function textareasizer(){$("#comment_body").css('max-width', textmaxwidth);return false;}

        //Other Miscellaneous Functions
        $('.comment-holder').hover(
        function(event) {
            $(this).addClass('highlight');
        },
        function(event) {
            $('.comment-holder').removeClass('highlight');
        }
        );

        function texthover()
        {
        $('.added_comment_body').hover(
            function(event) {
                $(this).parent().parent().addClass('highlight');
            },
            function(event) {
                $('.comment-holder').removeClass('highlight');
            }
        );
        return false;
        }
});


推荐答案

这是一个longshot,但是你运行某种跟踪脚本?像webtrends或coremetrics(或甚至你自己的一些脚本,这是全球寻找所有的点击)?之前,我遇到了类似的问题,其中初始点击被核心度量捕获。只是一个想法。

This is a longshot, but are you running some sort of tracking script? Like webtrends or coremetrics (or even some of your own script, that's globally looking for all clicks)? I ran into a similar problem a while ago, where the initial-click was being captured by coremetrics. Just a thought.

这篇关于Jquery点击事件不点火,但是第二次点击,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆