Yii2 验证码

没有用默认的layout  验证码点击不会改变 下面是静态页面代码

 1 <div class="col-sm-12 login">
 2                 <div class="row">
 3                     <div class="col-sm-6 col-md-offset-3">
 4                         <?php $form = ActiveForm::begin([
 5                             'fieldConfig' => [
 6                                 'template' => '<div class="form-group"><label for="inputPassword3" class="col-sm-4 control-label">{label}:</label> <div class="col-sm-8 b-margin10">{input}<label class="xz_b">{error}</label></div></div>',
 7                                 'inputOptions' => ['class' => 'form-control'],
 8                                 'labelOptions' => ['class' => ''],
 9                             ],
10                             'options' => ['class' => 'form-horizontal']
11                         ]); ?>
12                         <?= $form->field($model, 'username')->textInput(['placeholder' => '6~8个字符,可使用字母、数字,需以字母开头。']) ?>
13                         <?= $form->field($model, 'verifyCode')->widget(yii\captcha\Captcha::className(), [
14                             'template' => '<div class="col-sm-9 padding0">{input}</div><div class="col-sm-3 "><label >{image}</label></div> ',
15                             'imageOptions' => ['id' => 'checkpic', 'title' => '点击换图', 'style' => 'cursor:pointer', 'class' => 'yzm', 'onclick' => 'changing();'],
16                         ]) ?>
17 
18                         <?= $form->field($model, 'password')->passwordInput(['placeholder' => '6~16个字符,区分大小写。']) ?>
19                         <?= $form->field($model, 'replace_password')->passwordInput() ?>
20                         <div class="row text-center">
21                             <div class="col-lg-12">
22                                 <button type="submit" class="btn btn-primary btn-lg btn-neir">下一步</button>
23                             </div>
24                         </div>
25                         <?php $form = ActiveForm::end() ?>
26                     </div>
27                 </div>
28             </div>

在改页面中添加 一下js代码即可解决问题:

 1 <script type="text/javascript">
 2     //更改或者重新加载验证码
 3     function changing() {
 4         $.ajax({
 5             url: "/site/captcha?refresh",
 6             dataType: 'json',
 7             cache: false,
 8             success: function(data) {
 9                 $("#checkpic").attr('src', data['url']);
10             }
11         });
12     }
13 </script>

 

posted @ 2016-07-25 17:18  哦先生  阅读(233)  评论(0编辑  收藏  举报