weixin_33739646 2014-09-03 12:25 采纳率: 0%
浏览 21

加载AJAX之后的调用函数

I have jQuery script that helps me to mark rows in table. Also i have AJAX function that allows me to load additional data to this table. My idea is to call Picker function every time after AJAX used to let this data to be marked as well. It works, but very unstable - i can mark some blocks of loaded data, and can't mark other. And i can't catch where i am wrong.

<script>
var Picker = function() { // This is marker script
        $(".query, .schedule_query_table_highlight").click(function(){
        if ($(this).attr("class") == "schedule_query_table_highlight") {
            $(this)

.removeClass("schedule_query_table_highlight");
            $(this).addClass("query");
        }
        else {
        $(this).removeClass("query");
        $(this).addClass("schedule_query_table_highlight");
        }
        });
};

$(document).ready(function(){
    Picker();   
    $("#more").click(function(){
    $(".more_space").load("inquery_ajax.php?date=" + curr_year + "-" + curr_month + "-" + curr_date, function(){
            Picker();
        });         
        $(".more_space").addClass("loaded" + days);
        $(".more_space").removeClass("more_space");
        $(".loaded" + days).after("<x class=more_space></x>");
        $("#more").insertBefore(".more_space");
    });
});
</script>

UPD: FIDDLE

  • 写回答

1条回答 默认 最新

  • Didn"t forge 2014-09-03 12:35
    关注

    Don't know what is unstable but I assume unstable means here that the new content is not getting highlighted. As the content is dynamic, use event binding on document

    $(document).on("click",".query .schedule_query_table_highlight",function(){

    Example code:

    var Picker = function() { // This is marker script
            $(document).on("click",".query .schedule_query_table_highlight",function(){
            if ($(this).attr("class") == "schedule_query_table_highlight") {
                $(this)
    
    .removeClass("schedule_query_table_highlight");
                $(this).addClass("query");
            }
            else {
            $(this).removeClass("query");
            $(this).addClass("schedule_query_table_highlight");
            }
            });
    };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100