Change HTML code without refreshing the page

微笑、不失礼 提交于 2019-12-01 08:29:33

Using jQuery (a JavaScript library) you can utilize the load() function to load the contents of another HTML file on your server and place it anywhere you want on the current page without refreshing (so you can even replace the current HTML if you like).

jQuery:
http://jquery.com/

jQuery load():
http://api.jquery.com/load/


Alternative Suggestion:
However, I know you say you can't refresh the page, but, if the only reason is because you need to keep the text in the textbox, you could use a form to POST that text to another .jsp page (or even the same .jsp page, depending on how you go about it) where it will be available to you to use at your own discretion (to put it in another textbox, for example).

Maybe this will work for you.

<div id="mydiv"></div>
<a id="refresh">click</a>

<script>
$(function() {
  $("#refresh").click(function() {
     $("#mydiv").load("yourdomain.com/file.php")
  })
})

also see this:

http://woork.blogspot.nl/2007/10/how-to-change-text-using-javascript.html

Use JavaScript so you can make changes to the Document Object Model It is very easy to learn and very powerful.

Yes, this is possible. You should use JavaScript to change the HTML used to display the page.

You will probably find it useful to use a library such as JQuery.

You should use the javascript function document.getElementById (DIV THAT YOU WOULD LIKE TO PLACE IN).innerHTML = YOUR_TEXT;.

If you need a response from the server without reloading the page (you will still have to load, but the client will not notice), try using AJAX.

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