[英]Jquery Asp.net button disable
HTML代碼:
<asp:Button runat="server" ID="btnTest" Text="Test" OnClick="btnTest_Click" />
Jquery代碼:
$('[id$=btnTest]').click(function(){
$('[id$=btnTest]').attr('disabled', 'true');
});
代碼隱藏:
protected void btnTest_Click(object sender, EventArgs e)
{
//here not come.
}
btnTest事件后面的代碼不起作用?
我認為在click事件處理程序中禁用該按鈕會阻止回發。 嘗試在一段時間后執行禁用代碼:
$('[id$=btnTest]').click(function(){
var button = this;
setTimeout(function() {
$(button).attr('disabled', 'disabled');
}, 100);
});
嘗試使用jQuery類選擇器:
CssClass="MyButton"
添加到ASP.NET按鈕; disabled="disabled"
屬性 jQuery的:
$('button.MyButton').click(function(){
$(this).attr('disabled', 'disabled');
});
示例代碼使用了ends-with選擇器。 選擇器沒有錯誤。 你只需要改變這樣的代碼
$('[id$=btnTest]').click(function () {
$('[id$=btnTest]').attr('disabled', true);
});
我測試了這個並且工作正常沒有任何問題。
我可以解決你的問題: $(".classButton").prop('disabled','disabled'); and remove disabled: $(".classButton").prop('disabled', '');
$(".classButton").prop('disabled','disabled'); and remove disabled: $(".classButton").prop('disabled', '');
你不需要做以下事情:
btnTest.Enabled = False;
在代碼隱藏文件中? 這將導致回發,但它應該工作。
它不起作用,因為生成的HTML id與ASP.NET id不同。
所以btnTest將呈現為另一個Id。
一種快速的臟方法是運行頁面,查看HTML源代碼並找到按鈕生成的Id並將其作為jQuery函數中的一個arugment傳遞。
更好的方法是通過后面的代碼生成jQuery函數:
Literal1.Text = "$('[id$=" + btnTest.ClientId + "]').click(function(
{$(this).attr('disabled', 'disabled');});";
編輯 :我也忍不住意識到你的OnClick屬性應該指向btnTest_Click而不是btn_Click
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.