2013-02-26 30 views
1

當我點擊它,在這裏與我的代碼未禁用按鈕:禁用報告按鈕鏈接並不想禁用 - HTML5

<script type="text/javascript"> 
    function SetNewsCommentReportFlag(newsCommentId) { 
     $("#news-comment" + newsCommentId).text("This comment has been removed"); 
     $("#post-button" + newsCommentId).attr("onclick", "this.disabled=true;"); 
     var jqxhr = $.getJSON("<%= 
       Url.Action(
        "SetNewsCommentReportFlag", 
        "Home", 
        new { area = "News" } 
       ) 
      %>?newsCommentId=" + newsCommentId, function (data) { }); 
    } 
</script> 


<div class="news-comment" id="news-comment<%: Model.NewsCommentId %>"> 
    <% if (Model.Reported) 
    { 
     Model.NewsComment = "This comment has been removed";  
    } else %> 
    <%: Model.NewsComment %> 
</div> 
<div class="clear"></div> 
<div class="actions-right">  
    <a href="javascript:SetNewsCommentReportFlag(<%: Model.NewsCommentId %>);" 
     class="button" id="post_button<%: Model.NewsCommentId %>" 
    ><%: Html.Resource(Resources.Global.Button.Report) %></a>     
</div> 

這樣?:

<script type="text/javascript"> 
    function SetNewsCommentReportFlag(newsCommentId) { 
     $("#news-comment" + newsCommentId).text("This comment has been removed"); 
     $("#post-button" + newsCommentId).attr("onclick", "this.disabled=true;"); 
      var jqxhr = $.getJSON(
       "/News/Home/SetNewsCommentReportFlag?newsCommentId=" 
       + newsCommentId, function (data) { } 
      ); 
    } 
</script> 

<div class="news-post-list-item"> 
    <div class="news-post-user-info-wrapper"> 
     <div class="avatar"> 
      <img src="/ThemeFiles/Base/images/User/user-avatar.png" 
       width="52" height="52" alt="Avatar" /> 
     </div> 
     <div class="who-and-when-box"> 
      25/02/2013 13:20:56 
      <br /> 
      <br /> 
      Cecilia Torres Castro 
     </div> 
     <div class="news-comment" id="news-comment3"> 
      sdfsdf 
     </div> 
     <div class="clear"></div> 
     <div class="actions-right">  
      <a href="javascript:SetNewsCommentReportFlag(3);" 
       class="button" id="post_button3">Report</a>     
     </div> 
    </div>  
    <div class="clear"></div> 
</div> 

上午什麼我做錯了嗎? 感謝

回答

2

你不使用實際的按鈕,您正在使用錨標記:

<a href="javascript:SetNewsCommentReportFlag(3);" class="button" id="post_button3">Report</a> 

這些無法使用disabled=true禁用,僅適用於實際的按鈕。

由於您使用的是錨標籤而不是真正的按鈕,因此您必須稍微改變一下。

參見:

jQuery disable a link

How do I disable a href link in JavaScript?

您還必須給殘疾人 '按鈕' 一個新的CSS類,使它看起來太視力殘疾。

1

你添加一個onclick事件禁用它,但線後您已經禁用它

因爲您已經禁用了該元素,所以沒有事件觸發它。即使他們這樣做了,他們也會在被禁用的元素中產生相同的結果。我認爲你需要擺脫這一行:

$("#post-button").attr("disabled", "disabled"); 

此外,你必須在這行語法問題:

post_button.Attributes.Add("onclick", "this.disabled=true;"); 

將其更改爲:

$("#post_button").attr("onclick", "this.disabled=true;"); 
+0

我拿了出來,但也得到了一個錯誤添加線說無法獲得財產「增值」的價值? – 2013-02-26 10:47:27

+0

將該行更改爲'$(「#post_button」)。attr(「onclick」,「this.disabled = true;」);' – mattytommo 2013-02-26 10:48:38

+0

請參閱OP,報表按鈕仍然可點擊 – 2013-02-26 10:52:46