Yii,在提交按钮上附加一个 javascript 函数 [英] Yii, attaching a javascript function on submit button

查看:35
本文介绍了Yii,在提交按钮上附加一个 javascript 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个功能附加到我的提交按钮.但是我的代码似乎没有调用该函数.

I want to attach a function to my submit button. But my code doesn't seem to be calling the function.

基本上我想要它做的是,在提交表单时启用所有禁用的字段.

Basically what I want it to do is, enabling all disabled field when the form is being submitted.

这是我的代码:

<script>
function enableField() {
    $("#Booking_clientPackagedService_id").prop("disabled", false);
}
</script>


<?php
    echo CHtml::submitButton(Yii::t('app', 'Save'));
    $this->endWidget();
?>

#Booking_clientPackagedService_id 在完成某些操作后最初被禁用.但是当我点击提交时,我想启用该字段.我该怎么做?请指教,谢谢!:D

This #Booking_clientPackagedService_id initially is disabled after certain action being done. But when I click on submit, I would like to enable the field. How can I do it? Please advise, thanks! :D

编辑

所以我删除了提交按钮上的 onclick 事件,并根据 Kancho Iliev 的评论添加.

So I've removed onclick event on my submit button and added as per Kancho Iliev's comment.

$( "#booking-form" ).submit(function() {
  $("#Booking_clientPackagedService_id").prop("disabled", false);
});

但是还是不行.我错过了哪里?

But it is still not working. Where have I missed out?

推荐答案

移除 onclick 事件,并添加

Remove onclick event, and add

$("your_form_name").submit(function(){
   enableField();
}); 

这篇关于Yii,在提交按钮上附加一个 javascript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆