【问题标题】:Datepicker Ajax break日期选择器 Ajax 中断
【发布时间】:2012-09-24 13:16:37
【问题描述】:

我有一个 jQuery 日期选择器,它可以在 updateTable 中的 Ajax 完成时工作。 日历单元格中的数字消失并且阻止选择单元格。无论 updateTable 的结果是什么,都会发生这种情况。有什么问题?

<head>

<script type="text/javascript">

    $(document).ready(function () {

        initDatepicker();

        $("#btn").live('click', function (event) {

              $.ajax({
                url: '@Url.Action("Add")',
                type: 'POST',
                contentType: 'application/json',
                success: function (result) {
                        updateTable();
                }
            });
        });

  });

  function initDatepicker () {               
      $('.datepicker').datepicker();   
  };


  function updateTable() {          
        $.ajax({
            url: '@Url.Action("UpdateTable")',
            type: 'POST',
            contentType: 'application/json',
            success: function (result) {
                $("#table").append(result);
            },
        });
    };

</script>

</head>

<body>
      <div>
        @RenderBody()
      </div>

      <div id="table">
      </div>
</body>

【问题讨论】:

    标签: asp.net ajax datepicker actionresult


    【解决方案1】:

    您必须在更新 Ajax 之后重新初始化日期选择器,因为您更改了 DOM 结构并且之前的结构不再有效。因此,将表格更新为:

     function updateTable() {          
            $.ajax({
                url: '@Url.Action("UpdateTable")',
                type: 'POST',
                contentType: 'application/json',
                success: function (result) {
                    $("#table").append(result);
                    // here call again the init
                    initDatepicker();    
                },
            });
        };
    

    【讨论】:

    • @Mixel 对您的代码进行一些处理(如果您理解的话),不要等我来修复它,或者给我一个 url 来完整地检查它。 “它没有效果”的答案给了我任何线索,除了你什么都不知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 2023-04-08
    • 1970-01-01
    • 2014-04-22
    • 2020-02-05
    • 1970-01-01
    相关资源
    最近更新 更多