hkyizu 2011-06-16 11:13:25 3069次浏览 4条回复 0 0 0

大家看看我的这个代码 为什么在firefox中可以运行 在ie中就不行呢 ?多谢了 controlerl.php

public function actionDynamiccities()
{
    //$data=Location::model()->findAll('parent_id=:parent_id', 
    //array(':parent_id'=>(int) $_POST['country_id']));

     //为测试方便没有使用数据库支持,使用数据库请参看上面注释掉的代码。
     $list=array(
         1=>array(
            array("id"=>1,"name"=>"测试1"),
             array("id"=>2,"name"=>"测试2")
         ),
         2=>array(
            array("id"=>3,"name"=>"测试3"),
             array("id"=>4,"name"=>"测试4")
         ),
         3=>array(
            array("id"=>5,"name"=>"测试5"),
             array("id"=>6,"name"=>"测试6")
         ),
        );
     if(isset($list[$_POST['country_id']]))
     $data=$list[$_POST['country_id']];
     else
    $data=array(
        array("id"=>0,"name"=>"请先选择国家"),
         );




    $data=CHtml::listData($data,'id','name');
    foreach($data as $value=>$name)
    {
        echo CHtml::tag('option',
            array('value'=>$value),CHtml::encode($name),true);
    }
}

view.php

<?php
    echo CHtml::dropDownList('country_id','', array('0'=>'请选择',1=>'USA',2=>'France',3=>'Japan'),
    array(
        'ajax' => array(
        'type'=>'POST', //request type
        //'url'=>Yii::app()->createUrl('site/dynamiccities'),
        'url'=>Yii::app()->createUrl('qxinfo/dynamiccities'),
        'update'=>'#city_id', //selector to update
        'cache'=>false,
        //'data'=>'js:javascript statement' 
        //leave out the data key to pass all form values through
    ))); 
     
    //empty since it will be filled by the other dropdown
    echo CHtml::dropDownList('city_id','', array("请先选择国家"));

?>
您需要登录后才可以回复。登录 | 立即注册