问题
I am trying to load a portion of a page using jquery .load(), the the problem is, the div that I am trying to select is a variable
$('#additemsubmit').click(function(event){
event.preventDefault();
var location = $(this).parent();
var reload = '#' + $(this).parent().attr('id');
$(location).load("/index.php reload");
});
It seems I cant use variables for "location" and "reload"
回答1:
I think this is what you're looking for.
var reloadId = '#' + $(this).parent().attr('id');
$.get("/index.php", function(response) {
$(location).html($(response).find(reloadId));
});
回答2:
You need to use string concatenation to pass a selector to .load():
$(this).parent().load("/index.php#" + $(this).parent().attr('id'));
来源:https://stackoverflow.com/questions/8584762/jquery-load-part-of-page-select-by-variable-id