代码语言:javascript复制
方法一:
$this->registerJs(<<<JS
$('.refund-audit-btn').click(function(){
var id = $(this).attr('data-id');
//清空错误提示文字
$('.warning-active').html('');
//清空输入框的值
$('#refund-order-form ,form-group').find('.form-control').val('');
var form = $('#refund-order-form');
$.get('{$ajaxGetRefundInfoUrl}', {order_id: id}, function(rs){
form.find('[name=refund_amount]').val(rs['data']['is_refund_apply'] ? rs['data']['require_refund_amount'] : rs['data']['can_refund_amount']);
form.find('[name=refund_reason]').val(rs['data']['refund_reason']);
$('#refund_is_cancel').prop('checked', rs['data']['is_cancel']);
form.find('[name=refund_explain]').val(rs['data']['refund_explain']);
}, 'json');
form.find('#refund_order_id').val(id);
//点击输入框的提交按钮,防止数据丢失,和id丢失
$('.refund-btn').click(function() {
form.find('#refund_order_id').val(id);
})
});
$('#refund-order-form').on('beforeSubmit', function(){
var form = $(this);
$.post(form.attr('action'), form.serialize(), function(rs){
if(rs.status === 200)
{
form.trigger('reset.yiiActiveForm');
window.location.reload();
}
else
{
form.find('.warning-active').html('<i></i>' rs.message);
}
}, 'json');
return false;
});
JS
)?>
方法二:
代码语言:javascript复制$('#refund-order-form').trigger('reset.yiiActiveForm');//使用id