nik*_*sfi 2 javascript jquery json
我想做以下......
$('.showcomments').click(function()
{
$(this).parent().hide();
jQuery.getJSON('comments.json',function($data)
{
$(this).parent().append($data['value'])
//this is meant to be the instance of
//$('.showcomments') that has been clicked
});
});
Run Code Online (Sandbox Code Playgroud)
问题是getJSON的回调当然没有继承这个项目......但是我该如何做我想要的呢?
在变量中引用它:
$('.showcomments').click(function()
{
var $th = $(this); // References the clicked .showcomments
$th.parent().hide();
jQuery.getJSON('comments.json',function($data)
{
$th.parent().append($data['value']); // will reference the correct element
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
190 次 |
| 最近记录: |