0

使用萤火虫,我得到html如下-

<a rel="async-post" ajaxify="/ajax/pokes/poke_inline.php?uid=xxxxxxxxxxxxxxx&amp;pokeback=1" href="#" class="uiIconText"><i style="top: 0px;" class="img sp_1lbo22 sx_3b5b96"></i>Poke Back</a>

要获取 uid,我使用getElementsByTagName('a')函数然后查找ajaxify属性。下面是我的代码-

var elements = document.getElementsByTagName('a');

for (var i = 0; i < elements.length; i++) {
   var ajaxify = elements[i].ajaxify;
   if (!ajaxify) {
      continue;
   }
   var uid = ajaxify.match(/uid=([0-9]*)/)[1];
   alert(uid);
}

在 firebug 中运行我的代码后,我将undefined进入控制台,如下所示。

>>> var elements = document.getElementsByTagName('a'...ify.match(/uid=([0-9]*)/)[1];     alert(uid);  }

undefined

我怎样才能得到所有使用 javascript 戳的 id?

4

1 回答 1

0

There is a difference between an element's properties and an element's attributes. Most notably an <input/>'s value attribute represents the default value, whereas the value property is the current value.

Try using ajaxify = elements[i].getAttribute("ajaxify") and see if that helps.

于 2012-10-13T15:03:07.577 回答