我試圖通過 jQuery 在每次單擊錨標記“show”時獲取 li 元素的文本(1、2、3...),但似乎無法使其工作。這就是我正在處理的:HTML:<ul><li class="item_id">1</li><a class="show" href="#">SHOW</a></ul><ul><li class="item_id">2</li><a class="show" href="#">SHOW</a></ul><ul><li class="item_id">3</li><a class="show" href="#">SHOW</a></ul>JavaScript:/**This shows all values on each click and not only the current one**/$("a.show").click(function(){ $('li.item_id').each(function() { var item_id = $(this).text(); alert(testimonial_id); });});/**This shows the first value on each click and not only the current one**/$("a.show").click(function(){ var item_id = $("li.item_id").text(); alert(item_id);});提前致謝!
- 0 回答
- 0 關注
- 140 瀏覽
添加回答
舉報
0/150
提交
取消