稻草人369 2017-12-03 15:52:25 84次浏览 1条回复 0 0 0

我用select2写了一个三级联动
然后我需要点击按钮后,动态添加上面写的三级联动
可是复制后发现事件没有复制过来
求助!

具体代码如下:

<div class="awards">
                <div class="award">
                    <?php
                    $award_model= new backend\models\Tag();
                    $award_year  = "请选择时间";
                    $award_award="请选择奖项";
                    $specific_award="请选择具体的奖项";
                    $award = "获奖时间".Select2::widget([
                            //'class' => 'award_year',
                            'name' => 'award_year[]',
                            'data' => $award_model->getAwardList(7615),
                            'language' => 'zh-cn',
                            'hideSearch' => true,
                            'changeOnReset'=> true,
                            'options' => ['placeholder' =>$award_year, 'class'=>'award_year'],
                            'pluginOptions' => [
                                'allowClear' => true,
                                //'tags' => true,
                            ],
                            'pluginEvents' => [
                                'change' => 'function(event){
                                var _this = $(this);
                                 $.post("'.yii::$app->urlManager->createUrl('video/getaward').'&type=1&parent_award_id="+$(this).val(),function(data){
                                 _this.parents(".awards").find(".award_award").html(data);
                                 _this.parents(".awards").find(".specific_award").html("<option value=>请选择具体的奖项</option>");
                            })}',
                            ],
                        ])."<br>";
                    $award .="奖项".Select2::widget([
                            //'class' => 'award_award',
                            'name' => 'award_award[]',
                            'options' => ['placeholder' => $award_award, 'class' => 'award_award'],
                            //'data' =>$award_model->find()->where(['parent_id'=>$award_year_id])->asArray()->all(),
                            'language' => 'zh-cn',
                            'hideSearch' => true,
                            'changeOnReset'=> true,
                            'pluginOptions' => [
                                'allowClear' => true,
                                //'tags' => true,
                            ],
                            'pluginEvents' => [
                                'change'=>'function(event){
                                var _this = $(this);
                                $.post("'.yii::$app->urlManager->createUrl('video/getaward').'&type=2&parent_award_id="+$(this).val(),function(data){
                                 _this.parents(".awards").find(".specific_award").html(data);
                             });}',
                            ],
                        ])."<br>";
                    $award .="具体奖项".Select2::widget([
                            //'class' => 'specific_award',
                            'name' => 'specific_award[]',
                            //'data' => $award_model->find()->where(['parent_id'=>$award_award_id])->asArray()->all(),
                            'language' => 'zh-cn',
                            'hideSearch' => true,
                            'changeOnReset'=> true,
                            'options' => ['placeholder' => $specific_award, 'class' => 'specific_award'],
                            'pluginOptions' => [
                                'allowClear' => true,
                                //'tags' => true,
                            ],
                        ]);
                    echo $award."<br>";
                    ?>
            </div>
        </div>
        
        
        
 jq代码如下:
  
     $formatJs = <<<eof
     $('.more').click(function () {
       $(".awards:last").append($(".award:first").clone(true));
    });
 eof;
您需要登录后才可以回复。登录 | 立即注册