如何获得“课堂” C#或VB中HTML元素的属性 [英] How to get "class" attribute of an HTML element in C# or VB

查看:107
本文介绍了如何获得“课堂” C#或VB中HTML元素的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何获取HTML元素的class属性。

例如,对于这个HTML代码,这个C#代码运行良好:

 hElement.GetAttribute(id)//结果target_validate





但它不适用于class属性:

 hElement.GetAttribute(class)//结果





我使用C#WebBrowser控件。



< table id =target_validateclass =res_target cellpadding =1cellspacing =1> 
< tr>
< td class =vilcolspan =2> AVATAR(18 | 60)< / td>
< / tr>
< tr>
< th>用户:< / th>
< td>< a href =spieler.php?uid = 4018> Iman< / a>< / td>
< tr>
< th>时间:< / th>
< td> 0:31:49< / td>
< / tr>
< / table>

解决方案

用户className而不是class



喜欢GetAttribute(className)


嘿,



我不知道为什么,并没有理解html中的实际内容,而是使用htmlelement.GetAttribute(class)而不是htmlelement.GetAttribute(class)。我已经在我的应用程序中实现了它并且工作完美。

以下代码将返回res_target





 alert(文件。的getElementById( 'target_validate')的className); 


Hi,
How to get "class" attribute of an HTML element.
For example, for this HTML code, this C# code does well:

hElement.GetAttribute("id")  // Results "target_validate"



But it does not work for "class" attribute:

hElement.GetAttribute("class")  // Results ""



I use C# WebBrowser control.

<table id="target_validate" class="res_target" cellpadding="1" cellspacing="1">
	<tr>
		<td class="vil" colspan="2">AVATAR (18|60)</td>
	</tr>
	<tr>
		<th>User:</th>
		<td><a href="spieler.php?uid=4018">Iman</a></td>
	<tr>
		<th>Time:</th>
		<td>0:31:49</td>
	</tr>
</table>

解决方案

user "className' instead of "class"

like GetAttribute("className")


Hey,

I have no idea why, and doesnt make sense with what is actually in the html, but instead of htmlelement.GetAttribute("class"), use htmlelement.GetAttribute("classname"). I have it implemented as such in my app and works perfect.


the following code will return "res_target"


alert(document.getElementById('target_validate').className);


这篇关于如何获得“课堂” C#或VB中HTML元素的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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