简体   繁体   English

使用ajax加载方法加载后更改div内容

[英]Change div content after loading it with ajax load method

index.html page : index.html页面:

在此处输入图片说明

在此处输入图片说明

I am loading the new.html page using ajax load method and then tried to change the content of the div#rr but it did not work!我正在使用 ajax 加载方法加载new.html页面,然后尝试更改div#rr的内容,但没有成功!

any solution ?任何解决方案?

Try to call the function inside the ajax call function.尝试调用ajax调用函数内部的函数。

$('.container').load('new.html',function(){
      $('#rr').html('modified') 
});

next time please do not put image for code.下次请不要为代码放图片。

why your code $('#rr').html('modfied');为什么你的代码$('#rr').html('modfied'); is not working because you are calling the change before jquery ajax.load() method is able to load the content from your new.html and as result your id #rr is not found.不工作,因为您在 jquery ajax.load() 方法能够从您的new.html加载内容之前调用更改,结果您的 id #rr未找到。 So, instead of calling the modify code after the load statement call the modifying statement in your load()'s complete() as:因此,不要在 load 语句之后调用修改代码,而是调用 load() 的 complete() 中的修改语句,如下所示:

$('#btn').on('click', function () {
            $('.container').load('new.html', function () {
                $('#rr').html('modfied');
            });
        });

and please go through the jquery documentation for more info on how to use the functions Jquery Documentation for Load() funciton .并请阅读 jquery 文档以获取有关如何使用Load()函数的Jquery 文档功能的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM