Yii2验证码刷新按钮

I am using the default captcha implementation of the yii2 advanced framework. I have a problem: I want to add a refresh button to my captcha but I do not know how can I do it

Add captcha action to your controller, add captcha to your form, add field and validate rules for captcha to your model. Read more here.

And add button in view for update captcha image, like this:

<?php echo $form->field($model, 'captcha')->widget(Captcha::className(), [
    'imageOptions' => [
        'id' => 'my-captcha-image'
    ]
]); ?>

<?php echo Html::button('Refresh captcha', ['id' => 'refresh-captcha']);?>
<?php $this->registerJs("
    $('#refresh-captcha').on('click', function(e){
        e.preventDefault();

        $('#my-captcha-image').yiiCaptcha('refresh');
    })
"); ?>