简体   繁体   English

如何仅刷新HTML页面的特定部分?

[英]How to refresh just a specific portion of an HTML page?

I have one HTML file containing several <div> elements. 我有一个包含几个<div>元素的HTML文件。 I want to refresh just part of the page using either JavaScript or C#. 我想使用JavaScript或C#刷新页面的一部分。 Can someone help? 有人可以帮忙吗?

I am trying to do it this way: 我正在尝试这样做:

document.location.reload(document.getElementById("contentdiv"));

It reloads the whole page. 它将重新加载整个页面。 I wish to reload contentdiv . 我希望重新加载contentdiv If contentdiv is at the middle of the page then it should load only that part. 如果contentdiv位于页面的中间,则应仅加载该部分。

Thank you. 谢谢。

You could move the contents of everything you want reloaded into an external file, and either use the <iframe> tag and only refresh that frame, or you could use JavaScript and refresh the div with Ajax. 您可以将要重新加载的所有内容移动到外部文件中,并使用<iframe>标记仅刷新该框架,或者可以使用JavaScript并使用Ajax刷新div。

Ajax isn't that simple to explain in a short answer, but you can find plenty of information on it here: http://www.w3schools.com/Ajax/ajax_example.asp or if you use a framework like jQuery ajax is much easier. 用一个简短的答案解释Ajax并不是那么简单,但是您可以在这里找到很多信息: http : //www.w3schools.com/Ajax/ajax_example.asp还是使用诸如jQuery ajax之类的框架就足够了更轻松。

iFrames can be implemented (on mypage.html, for example) like so: <iframe src='mypagecontent.html'></iframe> and in mypagecontent.html you could use <script type='text/javascript'>window.location.reload();</script> to refresh the frame. iFrame可以这样实现(例如,在mypage.html上): <iframe src='mypagecontent.html'></iframe> ,在mypagecontent.html中,您可以使用<script type='text/javascript'>window.location.reload();</script>刷新框架。

Not sure if this is what you're looking for, but hope it helps somewhat. 不确定这是否是您要查找的内容,但希望对您有所帮助。

What ASP.NET Framework are you using? 您正在使用什么ASP.NET Framework? If you are using Web Forms, look into UpdatePanel 如果您使用的是Web窗体,请查看UpdatePanel

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

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