首页 新闻 会员 周边

如何获取HtmlElement中的属性值

0
悬赏园豆:50 [已解决问题] 解决于 2008-08-10 09:40
现在有这样一段Html代码<br>&lt;P class="new" other="123"&gt;<br>some text<br>&lt;/P&gt;<br><br>我已经获得了 HtmlElement ele(他就代表上面的这个Html元素)<br><br>string classAtt = ele.GetAttribute("class");<br>string otherAtt = ele.GetAttribute("other");<br><br>运行结果很奇怪,classAtt得不到想要的值,但是otherAtt可以得到期望的值。<br><br>希望大家可以帮忙看看。<br>
问题补充: 我用的是net2.0版本下的System.Windows.Forms.HtmlElement中的方法。 不是js或者 jquery ;) 我又发现了一个新的问题。 <a href="www.cnblogs.com"> 123 </a> 其中我要获得href的值也不行。 string s = htmlElement.GetAttribute("href"); 希望能给解答。
逖靖寒的主页 逖靖寒 | 菜鸟二级 | 园豆:265
提问于:2008-07-28 16:26
< >
分享
最佳答案
0
FF下使用 ele.getAttribute("class") ele.getAttribute("other") IE下使用 ele.getAttribute("className") ele.getAttribute("other") 为了避免判断浏览器,可以分别对待两个,使用下面这个兼容: ele.className ele.getAttribute("other") 注意 getAttribute 首字母要小写
丁学 | 专家六级 |园豆:18730 | 2008-07-28 16:48
其他回答(2)
0
jquery: ele.attr("class") ele.attr("other") 当然ele要是jquery对像
chaoren1641 | 园豆:110 (初学一级) | 2008-07-28 17:12
0
获得class使用ele.className就可以取得值了。
玉开 | 园豆:8822 (大侠五级) | 2008-07-29 08:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册