duanben1324 2018-10-05 06:36
浏览 73
已采纳

如何在单击多次后发出警报

Hello my lovely stackies,

After alot of research and no working solution I thought I would try my luck here. I have a button which POST a formular of a user to the my server. But my huge problem is, when the user clicks the button how much he wants, I get the formular as often as he clicked on it.

My button and send function is:

echo "<form name=\"myForm\" method=\"POST\" action=\"aktenerfassung.php?id=$id&mandnr=$mandnr&countBeleg=$countBeleg\"> 
";
echo "<p align=\"center\"><input id=\"absenden\" align=\"center\" type=\"submit\" value=\"Fehler korrigieren\" name=\"B1\"></p> 
";
echo "</form> 
";
unset($clsAktenerfassung);

My solution would be:

$(function() {

    $('absenden').on('click', function(e) {
        var trigger = $(this),
        clickCount = trigger.data('clickCount');

        clickCount++;

        trigger.data('clickCount', clickCount);
    }
        if(clickCount > 1) {
            alert('schon einmal klicken')
        }

    });

But I can still press the button how much I want and still don't get a alert. I dont even get a error message from PHP.

This should be the alert:

    if(clickCount > 1) {
        alert('schon einmal klicken')
    }

If anything is unclear or you need other information or this post already exists in stackoverflow, please tell me.

Thank you already!!

  • 写回答

1条回答 默认 最新

  • donglian1953 2018-10-05 06:41
    关注

    I was facing the same issue, and instead of catching "more than 1 click", I decided to disable the button and change its text with something like "Sending datas...". I used this simple code to achieve that, with jQuery :

    $('form[name=myForm]').submit(function()
    {
        $('#absenden').attr("disabled", true);
        $('#absenden').html("Sending datas...");
    });
    

    The event is fired on the form submission, instead of the submit button, because a user can submit with enter or return key.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办