如果您单击 this page 上的单元格, 它加载图像的较大版本。我正在努力实现同样的效果。
到目前为止我得到了什么:http://jsfiddle.net/8mYW9/
首先我知道有 "appear" <div>
是多余的 - 有没有利用 $(this)
的好方法?和 appendTo();
相反?
最终我的想法是获取被单击的 div 中包含的 anchor 的 ID,并将其附加到单元格。我应该做什么...?
最佳答案
如果您将 appear
元素的 ID 属性更改为 class,您可以这样做:
$(document).ready(function() {
$('#appear').hide();
$('.links').click(function() {
var $this = $(this);//cache the $(this) selector since it will be used more than once
$this.children('.appear').html('item id: ' + $this.children('a').attr('id')).fadeToggle('slow');
});
});
演示:http://jsfiddle.net/8mYW9/7/
顺便说一句,在 HTML 文档中不能有多个具有相同 ID 的元素。
关于javascript - jQuery:获取内容/innerhtml onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8685094/