将自定义属性添加到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.