使用jquery获取标签文本

我想做很简单的事情,但我不是成功的。我的asp.net页面上有按钮和标签,我想在点击按钮后获取标签文本。这是我的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="DynamicWebApplication.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title></title>    
    <script type="text/javascript">
        function f() 
        {
            var g = $('<%=Label1.ClientID%>').val();  // Also I tried .text() and .html()
            alert(g);
        }
    </script>
</head>

<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <p></p>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="f();"/>
        </div>
    </form>
</body>

解决方法

尝试这个:
var g = $('#<%=Label1.ClientID%>').val();

或这个:

var g = $('#<%=Label1.ClientID%>').html();

你错过了#

添加到头部:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...