jquery load part of page, select by variable ID

谁说我不能喝 提交于 2019-12-11 05:34:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!