简体   繁体   English

用户点击它时隐藏(或禁用)提交按钮

[英]Hide (or disable) submit button when user clicks on it

I am working on development of an application using CakePHP framework. 我正在使用CakePHP框架开发应用程序。

We all have clients that click several times on the submit button. 我们都有客户在提交按钮上多次单击。

How can I hide or (even better) disable the submit button when a user clicks on it? 当用户点击它时,如何隐藏或(甚至更好地)禁用提交按钮?

On the internet I found several Javascripts that can do it, but I need help to integrate it into my CakePHP script. 在互联网上我找到了几个可以做到的Javascripts,但我需要帮助将它集成到我的CakePHP脚本中。

Put this on the submit button: 把它放在提交按钮上:

onclick="this.disabled=true;return true;" 

example

    <input type=submit value='submit'
onClick='this.disabled=true;doSection(loading);return true;'> 

using jquery 使用jquery

 $("form").submit(function() {
            $(":submit", this).attr("disabled", "disabled");
          });

To follow up on what JapanPro said, if you want to place an onClick event in your submit field then you will need to use the form helper's submit function instead of the end() function. 要跟进JapanPro所说的内容,如果要在提交字段中放置onClick事件,则需要使用表单助手的提交函数而不是end()函数。 (CakePHP 1.2) (CakePHP 1.2)

<?php echo $form->submit('Submit', array('onClick' => 'alert("Test");')); ?>

This also means you will need to manually close the form. 这也意味着您需要手动关闭表单。

</form>

Id recommend using jQuery to handle this 我建议使用jQuery来处理这个问题

Try: 尝试:

<input data-disable-with="Saving..." name="commit" type="submit" value="Create new item">

Note the 请注意

data-disable-with="Saving..."

I've tried every suggestion on the web, including the ones above, and this is the only thing that seems to work on all browsers. 我已尝试过网络上的所有建议,包括上面的建议,这是唯一似乎适用于所有浏览器的建议。 I'm using CakePHP 1.2. 我正在使用CakePHP 1.2。

echo $form->submit('Submit', array('onClick' => 'this.disabled=true;this.form.submit();return true;'));

Hope this helps. 希望这可以帮助。

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

相关问题 Rails-用户单击提交按钮时如何更新表中的数据 - Rails - How update data in table when user clicks on submit button 是的,当用户单击提交按钮时,不会验证复选框 - Yup is not validating a checkbox when the user clicks the submit button 用户单击提交按钮时如何调用两个不同的网页? - How to call two different webpages when the user clicks submit button? 用户单击浏览器后退按钮时提交表单 - submit form when user clicks browser back button 当用户单击“提交”按钮时如何防止退出时发出JavaScript警报 - How to prevent javascript alert on exit when user clicks on submit button 当用户点击提交按钮时需要发布并关闭窗口 - Need to POST and close window when user clicks submit button 当用户单击“提交”按钮时,如何为变量分配任意值? - How to assign an arbitrary value to a variable when user clicks submit button? 用户单击“提交”按钮时将信息捕获到日志文件 - Capture information to log file when user clicks 'submit' button 当用户单击提交时,有没有办法将值从按钮传递到表单? - Is there a way to pass the value from a button to a form when the user clicks submit? 用户单击“关闭”按钮时要在特定时间段内隐藏的叠加层 - Overlays To Hide for Certain Period of Time When User Clicks Close Button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM