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

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

问题描述

我的下一个脚本,/现金流/箭头/调用获取数据,并与它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事件。 例如:

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

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

您可以阅读更多关于它这里

You can read more about it here

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

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