将自定义属性添加到HTML标签 [英] Add custom attribute to HTML tags
本文介绍了将自定义属性添加到HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将自定义属性添加到我的HTMLtags中,例如
I am adding custom attributes to my HTMLtags something like
<li customeId="1">
我要在IE中访问此自定义属性,但是在firefox中,我无法获取这些属性的值.关于如何在FireFox中访问自定义属性的任何建议.我正在使用HTML 4进行开发.
I am to access this custom attribute in IE but in firefox, I am not able to get the values of these attributes. Any suggestion on how to access custom attribute in FireFox or any other way. I am using HTML 4 for development.
要访问的代码:
var test = licollection[index].customeId;
谢谢 阿什瓦尼(Ashwani)
Thanks Ashwani
推荐答案
希望以下代码对您有所帮助.
Hopefully below code will be helpful for you.
<div id="navigation">
<ul>
<li customerId="1"></li>
<li customerId="2"></li>
<li customerId="3"></li>
</ul>
</div>
var x = document.getElementById('navigation');
if (!x) return;
var liCollections = x.getElementsByTagName('li');
for (var i=0;i<liCollections.length;i++)
alert(liCollections[i].getAttribute('customerid', 0));
它很清楚,您可以轻松理解它.
It's clear enough, and you can understand it easily.
这篇关于将自定义属性添加到HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文