English 中文(简体)
用 j子打上标签
原标题:Get text of label with jquery

我只想做非常简单的事情,但我不会成功。 我在纸面网页上贴有 but子和标签,我想在点击后拿到标签文本。 我的守则是:

<%@ 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();

页: 1

在标题部分增加:

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

引言

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

使用html功能。

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

你也找不到这个号码,以使其成为你重新寻找的身份证。 如果没有这个编号,它就寻找一种标签。

这里没有为我找到解决办法。 我在标签上增加了一个类别,并且能够选择这种方式。

<asp:Label ID=“Label1”

>。

正如其他人提到的那样,确保你装上 j。

Try:

<%=this.Label1.Text%>

试验文件。 ElementById ( <%=Label1.ClientID%> ).text or innerVD OtherWISE LOAD J RequestRY SCRIPT and put their code as it....

页: 1

var g = (<%=Label1.ClientID%> val(); 页: 1 我还尝试了案文()和.html()

页: 1 就像这样。

var g = (#<%=Label1.ClientID%>text();

also I do not prefer using this method

这是因为,如果你要求控制主页或封顶总页,或者你要求控制主页。 还控制了雷贝亚特。 而不论MVC。 这将造成问题。

页: 1 ......

(美元)

this is simple and clear. but do not forget to set

客户IDMode=“统计”

in your controls to remain with same ID name after render. that s because ASP.net will modify the ID name in HTML rendered file in some contexts i.e. the page is for Master page the control name will be ConetentPlaceholderName_controlID

I hope it clears the question Good Luck

该标签具有简单、具体价值(例如XXXX)并具有其操作性、公开输出源(浏览器)和参考XXXX,你将看到以下一些内容:<代码><span id=“mylabel”>XXX</span>;;span>(我认为它通常与“Label name in asp Code”),现在你可以通过内部超文本或Jery中另一种方法获得其价值。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签