JavaScript函数不返回值

JavaScript函数不返回值

本文介绍了JavaScript函数不返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主页上有一个按钮(授权),该按钮引发事件.然后,基于子页面,我授权票证.但是,当有人单击授权按钮时,我也必须进行确认,然后禁用授权按钮,以避免多次单击.

这是母版页中的HTML

I have a button (authorise) in master page, which raises event. Then based on child page, I authorise the ticket. However when someone clicks on authorise button, I have to confirm as well and then disable authorise button to avoid multiple clicks.

Here is HTML in masterpage

<asp:ImageButton ID="imgAuthorise" runat="server" ImageUrl="~/Images/Authorise.png" TabIndex="-1" ToolTip="Authorise" Visible="False" OnClientClick="return ToggleButton()" />


JavaScript方法


JavaScript Method

function ToggleButton() {
            var button = document.getElementById(event.srcElement.id);
            var returnValue = true;

            if (button.disabled) {
            }

            else {
                var check = confirm('Are you sure that you want to authorise?');
                if (check) {
                     button.disabled = true;
                    returnValue = true;
                }
                else {
                     button.disabled = false;
                    returnValue = false;
                }
            }
            return returnValue;
        }


现在,如果我用button.disabled注释行.函数返回正确的值,并且子页面成功执行事件.但是,如果我将button.disabled行放回去,则子页面不会订阅事件.

有人可以帮我吗?


Now, if I comment lines with button.disabled. function returns proper value and child page executes event successfully. However, if I place button.disabled lines back, then child page does not subscribe to event.

Can anyone help me please?

推荐答案


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
     <script type="text/javascript">
         function ToggleButton() {
             var button = document.getElementById('<%= imgAuthorise.ClientID %>');
             var returnValue = true;
             if (button.disabled) {
             }

             else {
                 var check = confirm('Are you sure that you want to authorise?');
                 if (check) {

                     returnValue = true;
                 }
                 else {

                     returnValue = false;
                 }
             }
             return returnValue;
         }


    </script>
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">

    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:ImageButton ID="imgAuthorise" runat="server" ImageUrl="~/Images/Authorise.png" TabIndex="-1" ToolTip="Authorise"  OnClientClick="return ToggleButton()" />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>



这篇关于JavaScript函数不返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 13:43