如何在ASP.NET中单击时获取标签文本 [英] How Can I get the Text of a Label When is Clicked in ASP.NET

查看:69
本文介绍了如何在ASP.NET中单击时获取标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在aspx页面上有12个标签



如果点击任何标签,我怎么能得到

的文本。 />
我尝试过使用每个标签的Click事件

但编码越来越多。

有没有其他选项或想法

来获取文字。

请协助任何想法。

使用以下代码获取每个标签点击事件的文字。

I have 12 labels
in a aspx page
how can i get the Text of
any label when is clicked.
I have Tried using the Click event of every label
But the coding is getting more.
Is there any Other option or idea
to fetch the text .
Please Assist any Idea.
Am using following Code to get the text on every click event of labels.

Dim str as String 
str =label1.text.tostring
Msgbox(str)



但是这样我必须在每12个标签上创建活动。

但我认为必须有另一种方法来处理这个

可能正在写一些功能。

请协助。


but this way I have to create events on every 12 labels.
But i think there must be some another way to handle this
may be writing some functions.
Please assist.

推荐答案





尝试使用jQuery。



标签生成一个div,所以这应该有效:



Hi,

try using jQuery.

A label generates a div, so this should work:


(#labelID).click( function (){
// 一些代码
});
(#labelID).click(function(){ //some code });





希望它有所帮助。



Hope it helps.


这篇关于如何在ASP.NET中单击时获取标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆