【发布时间】:2018-11-28 19:51:10
【问题描述】:
我有一个<a class="anchor"></a> 元素列表。为什么我不能让uniqueId() 处理它们?这是我所拥有的:
<a href="#" class="anchor">This</a>
<a href="#" class="anchor">This</a>
<a href="#" class="anchor">This</a>
<a href="#" class="anchor">This</a>
$(".anchor").each(function() {
$(this).uniqueId();
});
我也试过了:
this.uniqueId();
提前致谢。
【问题讨论】:
-
uniqueId()是一个 jQueryUI 方法,那么您是否包含了 jQueryUI 库以及 jQuery 本身?检查控制台是否有错误。虽然我建议如果您正确构建 HTML,则根本不需要自动生成id。 -
我用 JQuery UI 测试了它。它工作正常。
-
@zfrisch 更进一步,你不需要
each(): jsfiddle.net/RoryMcCrossan/g95aebxz -
@RoryMcCrossan 你是对的,但它直接来自 OP。只是想证明它有效。 :)
标签: javascript jquery jquery-ui