.click()事件仅在第一次执行 [英] .click() event executed only the first time

查看:96
本文介绍了.click()事件仅在第一次执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个脚本,/ cashflow / arrow /调用一个django视图,获取数据并使用它。然后它返回在html中加载的数据。

I have the next script, "/cashflow/arrow/" calls a django view that gets the data and works with it. Then it returns the data that is loaded in the html.

脚本在第一次点击中工作正常,但是当我想再次单击一个链接时,没有任何反应。

The script works fine in the first click, but when I want to click a link again, nothing happens.

<script>
$(document).ready(function(){   
    var prev_months = {{ prev_months }}
    var next_months = {{ meses_desp }}  

    function arrow(meses_ant, next_months) {
        $.get("/cashflow/arrow/", { prev_months: prev_months,   next_months: next_months},
          function(data){
            $("#cash_grid").html(data);      
         });
    }

    $("#dates_up").click( function() {
        if (prev_months > 0) {
            prev_months = prev_months - 1;
        }
        next_months = next_months + 1;
        arrow(prev_months, next_months);
    });
    $("#dates_down").click( function() {
        prev_months = prev_months + 1;
        if (next_months > 0) {
            next_months = next_months - 1;
        }
        arrow(prev_months, next_months);
    });

})

推荐答案

尝试使用 .live(click,function(){...}); 而不是点击事件。
例如:

Try to use .live("click", function() {...}); instead the click event. Eg:

$("#dates_up").live("click", function()...
$("#dates_down").live("click", function()...

您可以阅读更多关于它的信息 here

You can read more about it here

这篇关于.click()事件仅在第一次执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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