2014-11-04 84 views
1

我有一個按鈕,用於在我的aspx文件中調用後面的代碼。我試圖改變按鈕上的文本無濟於事。在類別爲html的按鈕上更改文本

HTML:

<button class="radius button" runat="server" id="buttonUpload" onServerClick="buttonUpload_Click"    >Execute SQL</button> 

這裏是JavaScript:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
<%--<asp:ScriptManager ID="scripman1" runat="server" EnablePageMethods="True"> 
</asp:ScriptManager>--%> 
<link rel="stylesheet" href="stylesheets/foundation.min.css"> 
<link rel="stylesheet" href="stylesheets/app.css"> 
<script src="javascripts/modernizr.foundation.js"></script> 

<style > 
    @import "css/datatables/demo_page.css"; 
    @import "css/datatables/demo_table.css"; 
    @import "Table Sorter/style.css"; 

</style> 
<script type="text/javascript" src="js/tablesorter/jquery.tablesorter.js"></script> 
<script type="text/javascript" src="js/vendor/jquery.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
      $("#buttonUpload").text('Save'); 
     }); 

我已經試過$("#buttonUpload").html('Save')。似乎沒有任何工作。

+0

在代碼運行時,元素是否存在於DOM中? – pmandell 2014-11-04 16:05:43

+0

放一個調試器;在該腳本中查看該按鈕是否存在。如果它不存在,那只是一個計時問題。 – GSaunders 2014-11-04 16:07:48

+0

是否加載了JQuery? – 2014-11-04 16:08:26

回答

0

我發現了問題是RUNAT「服務器」屬性

<button class="radius button" runat="server" id="buttonUpload" onServerClick="buttonUpload_Click"    >Execute SQL</button> 

當您刪除按鈕的文字更新罰款。

+1

這不是一個真正的「問題」 - 看起來也許你不明白到底發生了什麼。對於webforms中的服務器端訪問,您需要這樣做,但如果您不訪問服務器端的按鈕,則不需要。可能的**問題**是您指定的id不一定是webforms控件在呈現時獲得的id。有關如何爲服務器控件指定客戶端ID的信息,請查看此答案:http://stackoverflow.com/a/3304494/189937 – 2014-11-04 18:41:44

+0

謝謝澄清,我決定使用 techmakin 2014-11-04 19:03:08

1

等到DOM首先加載(和jQuery)。 .text().html()都將工作。

$(document).ready(function() { 
    $("#buttonUpload").text('Save'); 
});