简体   繁体   English

如何通过javascript区分按钮单击和按钮单击

[英]How to differentiate between button click and button click through javascript

I click submit button before test time is completed So I show a confirm message "Do you want to really Quit this test" and I click the submit button when Time is completed (Time left is 00:00:00) through javascript, but then also it asks user with confirm message Which I do not want to show on completion of time, How can I achieve this? 我在测试时间结束之前单击提交按钮,所以我显示一条确认消息“您是否真的要退出此测试”,当时间完成(剩余时间为00:00:00)时,我通过javascript单击了提交按钮,但是还会向用户询问确认消息,我不想在时间结束时显示,该如何实现? This is my button 这是我的按钮

<asp:Button ID="btnSubmit"  class="btn" runat="server"
                                    OnClientClick="return confirm('Do you  want to really Quit this test');" Text="Submit Test"
                                    OnClick="btnSubmit_Click" />

This is javascript through which I call Click event when test time is over 这是javascript,测试时间结束后,我通过它调用Click事件

<script type="text/javascript">
         function 
    display() {

                var hours = document.getElementById('<%=HidH.ClientID %>');
                var minutes = document.getElementById('<%=HidM.ClientID %>');
                var seconds = document.getElementById('<%=HidS.ClientID %>');

                if (hours.value == 0 && minutes.value == 0 && seconds.value == 0) {
                    alert("Time Given For this Test is Over");
                    document.getElementById('btnSubmit').click();
                 }
                } 
   </script>

Instead of binding click event inline call a function where you will prompt user for confirmation and make it option depending on timeout. 无需绑定内联单击事件的函数,而是调用一个函数,在此函数中将提示用户进行确认,并根据超时将其设为选项。

Change 更改

OnClientClick="return confirm('Do you  want to really Quit this test');" 

To

OnClientClick="return myConfirmFun()" 

Define myConfirmFun as under. 在下面定义myConfirmFun。

var showConfirm = false; // defind gloablly

function myConfirmFun()
{
    if(showConfirm) 
    {
        showConfirmm = false; 
        confirm('Do you  want to really Quit this test');
    }
}

In the display function 在显示功能

if (hours.value == 0 && minutes.value == 0 && seconds.value == 0) {
    showConfirm = false;
    alert("Time Given For this Test is Over");
}
else
    showConfirm = true;

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

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