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 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?