【问题标题】:Disable multiple clicks on save button in jquery-easyui在 jquery-easyui 中禁用多次单击保存按钮
【发布时间】:2017-07-24 06:03:42
【问题描述】:

在easyui中创建新用户时如何禁用多次单击保存按钮,同时将请求发送到php以将其插入数据库中

function saveUser() {

  $('#fm').form('submit', {
    url: url,

    onSubmit: function() {
      return $(this).form('validate');
    },

    success: function(result) {

      if (result === 'exists') {
        $.messager.alert('Alert', 'Name already exists!\nPlease enter different Name', 'info');
        $('#fm').form('clear');
      } else {
        $('#dlg').dialog('close'); // close the dialog
        $('#dg').datagrid('reload'); // reload the user data
      }
    }
  });
}

直到响应没有从 php 文件到达,我不希望发送另一个请求。

【问题讨论】:

  • 放置你的用户界面代码
  • 你已经尝试了什么?一种(公平地说可能不是最干净的)解决方案可能是在单击按钮时禁用按钮,获取响应,启用按钮,返回/显示它。

标签: javascript php jquery jquery-easyui


【解决方案1】:

您可以在单击提交按钮后立即禁用它,

请查看以下代码,希望对您有所帮助:

function saveUser() {

  $('#fm').form('submit', {

    url: url,

    onSubmit: function() {
       //Code to Disable the submit button comes here.
       $("#SubmitButton").attr('disabled',true);//Assuming SubmitButton is the ID of the button.
      return $(this).form('validate');
    },

    success: function(result) {

      if (result === 'exists') {
        $.messager.alert('Alert', 'Name already exists!\nPlease enter different Name', 'info');
        $('#fm').form('clear');
      } else {
        //If you want to allow the user to click on the Submit button now you can enable here like this :
        $("#SubmitButton").attr('disabled',false);
        $('#dlg').dialog('close'); // close the dialog
        $('#dg').datagrid('reload'); // reload the user data
      }
    }
  });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多