2
我覺得我完全錯過了某些東西,但我無法弄清楚是什麼。我嘗試通過.get()獲取通過索引指定的項目的數據屬性。不過,我似乎無法做到這一點:從get()中找到的元素獲取數據屬性
var int = 1,
\t \t 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>
缺少什麼我在這裏?爲什麼會發生?