Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何设置引导按钮,使其在一次单击中被禁用_Javascript_Jquery_.net_Twitter Bootstrap_Button - Fatal编程技术网

Javascript 如何设置引导按钮,使其在一次单击中被禁用

Javascript 如何设置引导按钮,使其在一次单击中被禁用,javascript,jquery,.net,twitter-bootstrap,button,Javascript,Jquery,.net,Twitter Bootstrap,Button,引导按钮用于将一些数据提交到SQL server数据库中。我希望在用户单击按钮一次时将其禁用。但奇怪的是, 我必须“快速”点击按钮两次,使其禁用。但无论您如何单击onCommand c#函数,它都运行良好。 这是代码 <div style="margin-top:5px; margin-bottom:10px; text-align:center; "> <asp:UpdatePanel ID="Ajax_SubmitReportRoom" r

引导按钮用于将一些数据提交到SQL server数据库中。我希望在用户单击按钮一次时将其禁用。但奇怪的是, 我必须“快速”点击按钮两次,使其禁用。但无论您如何单击onCommand c#函数,它都运行良好。 这是代码

      <div style="margin-top:5px; margin-bottom:10px; text-align:center; "> 
          <asp:UpdatePanel ID="Ajax_SubmitReportRoom" runat="server" UpdateMode="Conditional">
          <ContentTemplate>
          <asp:LinkButton ID="SubmitReportRoom" type="button" CssClass="btn btn-info SubmitReport" OnClientClick="toggleVisibility();" runat="server" Text="Submit" OnCommand="SubmitReport_Command" CommandName="ReportRoom" CausesValidation="true" />
          </ContentTemplate>
          <Triggers>
          <asp:AsyncPostBackTrigger  ControlID="SubmitReportRoom" />
          </Triggers>
          </asp:UpdatePanel>
     </div>

     <script type="text/javascript">
     function toggleVisibility(){
         $('.SubmitReport').addClass('disabled');
         //$('.SubmitReport').attr("data-toggle", "modal"); // for some reason this is needed to disable the button but this causes OnCommand function to stop running
     }

函数toggleVisibility(){
$('.SubmitReport').addClass('disabled');
//$('.SubmitReport').attr(“数据切换”,“模式”);//出于某种原因,禁用按钮时需要此选项,但这会导致OnCommand函数停止运行
}

请尝试.attr('disabled','disabled')而不是addClass

尝试以下操作:

$("#SubmitReportRoom").on("click", function(){
    if (e.handled !== true) {
      e.handled = true;
      $("#SubmitReportRoom").prop("disabled", true);
    }
});
试试这个

function toggleVisibility(){
    $('.SubmitReport').addClass('disabled').attr("data-toggle", "modal");
}

在本例中,禁用按钮的简单代码在单击事件时调用toggleVisibility函数,并在下面的代码中处理

function toggleVisibility(){
    $('button').prop("disabled", true);
}

我只是试了一下,但结果还是一样。我刚刚编辑了我的问题。该按钮位于updatePanel内部,因此它可以触发AJAX。可能asp.net会添加一个事件处理程序。能否尝试添加单击事件?希望您可以有条件地防止默认单击?啊,现在OnCommand函数不起作用了。我不明白为什么。