jQuery datepicker only works once and is not shown the second time

后端 未结 10 1214
庸人自扰
庸人自扰 2021-01-02 06:32

ASP.NET MVC3 / jQuery 1.9.1 / jQuery UI 1.10.2

I\'ve got a page on which I open a modal dialog after clicking on an Ajax.ActionLink. Inside this dialog

10条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 06:56

    It is opened via an Ajax.ActionLink which updates a target id (div) via the UpdateTargetId property. The controller action returning the contents for the modal dialog queries a web service and then returns a partial view with a populated model.

    then you need to call the datepciker function again after the partial view is populated... inside callback function of ajax(if you are using that)...

     $.ajax({
        success:function(){
            //your stuff
           $("#datepicker").datepicker();
         }
     });
    

    datepikcker won't be able to call a function for dynamically added element... since your target div is not present at the time when the datepicker is first called... you need to call the datepicker function again for if to work for added target DIV

    updated

      OnSuccess = "openPopup()"
      .....
    
     function openPopup(){
       //your codes
        $("#datepicker").datepicker(); //call date picker function to the added element again
    }
    

提交回复
热议问题