从使用 get() 找到的元素中获取数据属性
Get data-attribute from element that's found with get()
我觉得我完全错过了什么,我不知道是什么。我尝试通过 .get() 获取使用索引指定的项目的数据属性。但是,我似乎做不到:
var int = 1,
selector = $("a");
console.log(selector.get(int));
console.log(selector.get(int).data("banana")); // Uncaught TypeError: selector.get(...).data is not a function
console.log(selector.get(int)[0].data("banana")); // Uncaught TypeError: selector.get(...).data is not a function
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" data-banana="5">Hello</a>
<a href="#" data-banana="2">there</a>
我在这里错过了什么?为什么会这样?
我觉得我完全错过了什么,我不知道是什么。我尝试通过 .get() 获取使用索引指定的项目的数据属性。但是,我似乎做不到:
var int = 1,
selector = $("a");
console.log(selector.get(int));
console.log(selector.get(int).data("banana")); // Uncaught TypeError: selector.get(...).data is not a function
console.log(selector.get(int)[0].data("banana")); // Uncaught TypeError: selector.get(...).data is not a function
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" data-banana="5">Hello</a>
<a href="#" data-banana="2">there</a>
我在这里错过了什么?为什么会这样?