简体   繁体   English

在javascript中找到html控件的类型

[英]find the type of html controls in javascript

How to find the control type in javasccript?. 如何在javasccript中找到控件类型? Say if i have an ASP.NET LinkButton and i wanna find control type from the javascript. 假如我有一个ASP.NET LinkBut​​ton,我想从javascript中找到控件类型。 How can i do that. 我怎样才能做到这一点。 I tried using typeof(), but it giving me an object back. 我尝试使用typeof(),但它给了我一个对象。 and i tried 我试过

var control = document.getElementById(Id);//Id is the ClientId of the Linkbutton
alert(control.type);//this is empty.

You can't find the controltype as in ASP.NET in javascript I think. 我认为你无法在javascript中找到ASP.NET中的控件类型。 There is the attribute tagName that may help you: 有一个属性tagName可以帮助您:

control.tagName returns the HTML tagname. control.tagName返回HTML标记名。 If you really want the ASP control name, you can try to put the controlname in for example the class attribute. 如果您确实需要ASP控件名称,可以尝试将控件名称放在例如class属性中。

you can't get control type directly by javascript. 你无法通过javascript直接获得控件类型。 you can try to use some serverside code to determine control class name: 您可以尝试使用一些服务器端代码来确定控件类名称:

var cType = '<%= Type.GetType(yourControlServerName).ToString() %>';
alert(cType);

LinkButton is a server side type of control, but in the client side (javascript) there is not a LinkButton but the HTML tags rendered by that control which probably include tags. LinkBut​​ton是一种服务器端类型的控件,但在客户端(javascript)中没有LinkBut​​ton,而是由该控件呈现的HTML标签,可能包含标签。

So, in the javascript it makes not sense to talk about LinkButtons. 所以,在javascript中谈论LinkBut​​tons是没有意义的。

Probably there is a better solution for what you are trying to accomplish. 对于您想要实现的目标,可能有更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM