用户单击后禁用按钮(在数据列表中)

Disable a button (in a data list) after a single click by user

本文关键字:数据 列表 按钮 单击 用户      更新时间:2023-09-26

我想禁用数据列表行中包含的按钮。是否可以在用户单击一次按钮后禁用该按钮?如果是这样,有人可以建议我如何实现这一目标。

<asp:DataList ID="DataList1" runat="server" DataKeyField="Qno" OnItemCommand="DataList1_OnItemCommand"
        DataSourceID="SqlDataSource1">
        <ItemTemplate> <asp:RadioButton ID="RadioButton1" runat="server" Text='<%# Eval("Ans1") %>' GroupName="qu" />
            <br />
            <asp:RadioButton ID="RadioButton2" runat="server" Text='<%# Eval("Ans2") %>' GroupName="qu" /> <asp:Button ID="Button2" runat="server" Text="Submit" CommandName="Validate" />
            <br />
        </ItemTemplate>

我与ASP无关,但是如果你想要javascript(jQuery)解决方案,那么你可以做一些类似的事情

$(.once-clickable-button).click(function(){ 
  $(this).attr("disabled", "disabled");
  // if needed - do what it is supposed to do
});

(当然,在按钮上添加类"一次可点击的按钮"或选择适合您的名称)

<script type="text/javascript">
   function checkEnableSubmit() {
     document.getElementById("Button2").disabled = true;
   }
</script>

如果要禁用按钮,请在 OnClick 事件上调用此方法

使用 javascript,您可以执行以下操作:

document.getElementById("buttonID").disabled = true