简体   繁体   English

Yii,在提交按钮上附加一个javascript函数

[英]Yii, attaching a javascript function on submit button

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. 基本上,我要执行的操作是在提交表单时启用所有禁用的字段。

This below is my code: 这是我的代码:

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


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

This #Booking_clientPackagedService_id initially is disabled after certain action being done. 完成某些操作后,此#Booking_clientPackagedService_id最初被禁用。 But when I click on submit, I would like to enable the field. 但是,当我单击提交时,我想启用该字段。 How can I do it? 我该怎么做? Please advise, thanks! 请指教,谢谢! :D :d

EDIT 编辑

So I've removed onclick event on my submit button and added as per Kancho Iliev's comment. 因此,我已经删除了我的“提交”按钮上的onclick事件,并根据Kancho Iliev的评论进行了添加。

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

But it is still not working. 但是它仍然无法正常工作。 Where have I missed out? 我在哪里错过了?

Remove onclick event, and add 删除onclick事件,然后添加

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

This is the correct way of attaching a submit function: 这是附加提交功能的正确方法:

$(function() {
    $("#formName").submit(function() {
        alert("hi");
        //do whatever 
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM