Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 单击-jquery时仅重新加载特定类的元素_Function_Reload_Elements_Jquery - Fatal编程技术网

Function 单击-jquery时仅重新加载特定类的元素

Function 单击-jquery时仅重新加载特定类的元素,function,reload,elements,jquery,Function,Reload,Elements,Jquery,我具有单击后重新加载页面的功能: $('#reload').click(function () { location.reload(); }); 我应该放什么来代替location.reload()以便仅重新加载aaa类的元素 尝试了$('.aaa').reload()-不起作用。您可以使用将内容加载到元素,也就是说,前提是您有一个返回要加载到元素中的html的url。不能将元素重新加载到旧状态,因为HTML是无状态的,除非手动管理状态 $('#reload').click(fun

我具有单击后重新加载页面的功能:

$('#reload').click(function () {
   location.reload();
 });
我应该放什么来代替
location.reload()以便仅重新加载aaa类的元素

尝试了
$('.aaa').reload()-不起作用。

您可以使用将内容加载到元素,也就是说,前提是您有一个返回要加载到元素中的html的url。不能将元素重新加载到旧状态,因为HTML是无状态的,除非手动管理状态

  $('#reload').click(function () {
      $('.aaa').load(url); //url which returns you the content of the html.
 });
或者其他方法可以是将元素的先前状态存储在localstorage/cookie/data cache等中,并在单击时重新填充

第二种方法的一个例子是:

 $('#reload').click(function () {
      $('.aaa').replaceWith($('.aaa').data('cache')); //just replace itself with one in the data cache
 });

$('.aaa').data('cache', $('.aaa').clone(true)); //on load of the page save the current element in data cache, for later use

要从何处重新加载?你有一个url来获取该元素的内容吗?它就在页面htmlcorrect answer上。唯一的问题是我问错了问题,但你的回答肯定有帮助。谢谢。这是一个很棒的答案!我很惊讶它没有更受欢迎,因为它非常有用,即使在3年后