我有以下代码,如果单击#test 按钮,将在#currentActivities 中生成内容。还有另一个#hide 按钮,可以简单地隐藏#currentActivities 的内容。我的问题是如果我第一次单击#test,我可以获得内容。当我单击#hide 时,#currentActivities 的内容可以按预期隐藏。但是,如果我再次单击#test,则无法生成内容。我曾尝试$('#currentActivities').empty();
在开始时添加,但似乎不起作用。谁能帮助我并指出我的问题?
$("#test").click(function() {
$('#currentActivities').empty();
$.ajax({
type: "GET",
dataType: "jsonp",
jsonpCallback: "jsoncallback",
data: {
//some data here
},
url: "http://mydomain.com/check.php?jsoncallback=?",
success: function(data) {
$.each(data, function(index, student) {
$('#currentActivities').append(
'<li><a href="tutor_student_detail.html" data-name="' + data[index].data.NameA + '">' +
'<h4>' + data[index].data.NameA + '</h4>' +
'<p>' + data[index].data.NameA + '</p>' +
'</a></li>');
$("li a").click(function() {
window.localStorage["view"] = $(this).data('name');
window.localStorage["Request"] = "true";
}); //end of li a
});
$('#load2').hide();
$('#filter').show();
$('#currentActivities').listview('refresh');
},
error: function(jqXHR, textStatus) {
alert("Request failed: " + textStatus);
}
});
return false;
});