2013-02-13 298 views
0
<% using (Html.BeginAbsoluteRouteForm("PetDetail", new { controller = "Customers", action = "SavePetSitterRestrictionsAndPermissions", ownerKey = Model.Owner.Key, petKey = Model.Key })) 
     { %> 

       <button type="submit" class="actionButton default"> 
       Save</button> 

    <% } 
} %> 

我上面的代碼爲submit a form,我需要在disable a save button之後點擊保存按鈕。點擊提交後按鈕

通過使用jquery該怎麼做?

我試過的東西看起來像下面:

var clickedBttn=$('.actionButton.default[type=submit][clicked=true]').val() 

if (clickedBttn) 
{ 
//btton disable code here 
} 

never fires上面的代碼。

回答

1

您應該簡單地註冊單擊事件該按鈕:

$('.actionButton.default[type=submit]').click(function(){ 
    $(this).prop("disabled", true); 
}) 

另外,我知道沒有像[卡嗒一聲]屬性,因此,如果不設置某處,jquery將在這裏找不到任何東西$('.actionButton.default[type=submit][clicked=true]')

+0

當我註冊了「點擊事件」它會激發我的正常「表單提交」操作嗎?它發生的順序是什麼?點擊後是點擊還是什麼? – Sampath 2013-02-13 10:12:30

+0

在實際提交之前點擊。但我不認爲這應該是一個問題。實際上,你可以將它改爲'$(「#PetDetail」)。submit(function(){$('。actionButton.default [type = submit]')。prop(「disabled」,true);})' – 2013-02-13 10:14:50

+0

我可以使用上面提到的代碼與我上面提到的我的普通html代碼,還是應該更改我的html代碼(表單郵政編碼)?這裏「#PetDetail」是表單ID嗎? – Sampath 2013-02-13 10:21:43

0

嘗試......

$('.actionButton').click(function(){ 
    $('p').text("Form submiting....."); 
    $('input:submit').attr("disabled", true); 
}); 
+2

'$(「輸入:提交」)' - 這將禁用所有提交按鈕,不僅保存按鈕 – 2013-02-13 10:09:53

0

簡單地獲取對點擊按鈕的文本屬性的引用不會做你想要的不幸的事情。一些額外的研究將在這裏幫助。我建議在點擊閱讀了()jQuery的方法 - http://api.jquery.com/click/

$('.actionButton.default[type=submit][clicked=true]').click(function() { 
    // button disable code here 
    $(this).attr("disabled", true); 
});