Ajax|javascript
After referring to some previous practices, the use of a number of workarounds, and add some additional tags to better implement the innerHTML JavaScript operation, so that the various modules of the page
Good interaction, and data sharing.
Let's look at the following example:
<script>
var title = "Hello";
var time = 0;
var author = "Vickenyang";
var email = "ycg01@software.nju.edu.cn";
</script>
<body>
<div id= "Div_1" >
<span style= "Display:none" >hidden</SPAN>
Hehe
<!--bs-->
<script>
document.write ("a");
</script>
<!--es-->
This is the first page!
<br>
<!--bs-->
<script>
time++;
document.write (Title+time+author);
alert (time);
document.write ("<br>---------------");
</script>
<!--es-->
<input type= "text" name= "test" value= "Test" >
</div>
<script>
function Refreshdiv (DIV)
{
var html = "";
function Changediv ()
{
var oldwrite = document.write;
var oldwriteln = Document.writeln;
document.write = function (str)
{
HTML + str;
}
Document.writeln = function (str)
{
HTML + + str + "\ n";
}
var htmltmp = div.innerhtml;
IE default capitalization, add to support Firefox, in the ointment, will replace all the script value, if only IE application, can log off this trip
Htmltmp = Htmltmp.replace (/script/gi, "script");
alert (HTMLTMP);
var pos_1 = 0;
var pos_2 = 0;
Pos_1 = Htmltmp.indexof ("<SCRIPT>", pos_1);
while (Pos_1!=-1)
{
HTML + htmltmp.substring (pos_2,pos_1);
var Pos_3 = Htmltmp.indexof ("</SCR" + "ipt>", pos_1);
HTML + htmltmp.substring (pos_1,pos_3+ "<-SCRIPT>". length);
pos_2 = pos_1+ "<SCRIPT>". Length;
Eval (htmltmp.substring (Pos_2,pos_3));
Pos_2 = Htmltmp.indexof ("<!--es-->", Pos_3);
Pos_1 = Htmltmp.indexof ("<SCRIPT>", pos_1+1);
}
HTML + htmltmp.substring (pos_2,htmltmp.length);
document.write = Oldwrite;
Document.writeln = Oldwriteln;
}
Eval ("Changediv ();");
div.innerhtml = html;
}
function Change ()
{
Refreshdiv (document.getElementById (' div_1 '));
}
function Change2 ()
{
document.write ("over");
}
</script>
<input type= "button" value= "Change" >
<input type= "button" value= "Change2" >
</body>
Steps:
1. In the first line of Div plus <span style= "Display:none" >hidden</SPAN> (do not do so, IE will ignore the first JS)
2. In the div before and after each JS plus <!--bs--><!--es--> mark.
Principle: The code will tell you. If you have a better way, please email and discuss it together.
Fill
function Refreshdiv (DIV)
{
var html = "";
If recursive calls are used in a particular application, the HTML here can be defined as a global variable so that the last page is displayed when the recursive refresh is guaranteed. (For example, if you want to have asynchronous load data in Ajax, you can use it when specifying the refresh div in the callback function)
The following examples have specific applications: an AJAX-based, personalized web building prototype
Http://bbs.nju.edu.cn/file/Y/ycg/obj.rar