1

我写了这段代码:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/javascript">
// <![CDATA[

    function btnClient_onclick() {
        document.getElementById("lblClient").innerText = "Changed";
        document.getElementById("lblServer").innerText = "Server";

    }

// ]]>
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    Welcome to ASP.NET!
</h2>
<p>
    <asp:Button ID="btnServer" runat="server" onclick="btnServer_Click" 
        Text="Server" />
    <asp:Label ID="lblServer" runat="server" Text="Server"></asp:Label>
</p>
<p>
    <input id="btnClient" type="button" value="Client" onclick="return btnClient_onclick()" />
    <asp:Label ID="lblClient" runat="server" Text="Client"></asp:Label>
</p>
</asp:Content>

当我运行它时,得到了这个错误:无法设置未定义或空引用的属性'innerText'

4

2 回答 2

0

ClientIDMode 为静态

在两个标签上,看看是否有效

于 2014-06-02T20:07:46.177 回答
0

尝试这个

document.getElementById("lblClient").setAttribute('text', "Changed");
于 2014-06-02T20:15:10.053 回答