Home  >  Article  >  Backend Development  >  Yii: Using CJuiDatePicker date control in ajax refresh

Yii: Using CJuiDatePicker date control in ajax refresh

WBOY
WBOYOriginal
2016-08-08 09:25:081081browse

If the CJuiDatePicker component is used in the ajax update interface, please note that you need to re-execute the jquery ui datepicker JS initialization script for the date control to take effect.

In addition, the datepicker control depends on the jQuery UI plug-in, so the CSS and JS files of jquery ui need to be registered. The specific code is as follows:

<?php 
    Yii::app()->getClientScript()->registerCoreScript('jquery');
    Yii::app()->getClientScript()->registerCoreScript( 'jquery.ui' ); 
    Yii::app()->clientScript->registerCssFile(
        Yii::app()->clientScript->getCoreScriptUrl().
        '/jui/css/base/jquery-ui.css'
    );   
    Yii::app()->clientScript->registerCssFile(
        Yii::app()->clientScript->getCoreScriptUrl().
        '/jui/css/base/jquery.ui.datepicker.css'
    );  
?>

Reinstall the date control initialization script:

$.ajax({
<span></span>url:'<?php echo $this->url?>',
<span></span>type:'post',
<span></span>data: '&days=' + days,
<span></span>dataType:'text',
<span></span>success:function(data){
<span></span>  $("#list").html(data);
        <span></span>  $('#begin_time').datepicker(jQuery.extend({showMonthAfterYear:false},jQuery.datepicker.regional['cn'],{'dateFormat':'yy/mm/dd'}));            
<span></span>}
});

If you use the date control in CGridView, you can put the reinitialization operation in the afterAjaxUpdate callback.

The above introduces Yii: using the CJuiDatePicker date control in ajax refresh, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn