Project requirements:
The list on the left shows the newly added job opportunities, and the list on the right shows an IFRAME. In this IFRAME, you can add new job opportunities,
You are required to refresh the job opportunity list on the page outside IFRAME in real time after successful addition.
: Latest list on the left
Implementation:
Write the datalist object on the page to implementCodeAs follows:
< Script Type = " Text/JavaScript " >
Function Datalist (){
This . Datasource = Null ;
This . Table = Null ;
This . Maxitems = 5 ;
}
Datalist. Prototype = {
Initialize: Function ()
{
If ( This . Datasource && This . Table)
{
VaR Table = $ Get ( This . Table );
VaR Totalrows = Table. Rows. Length
For ( VaR I = 1 ; I < Totalrows; I ++ )
{
Table. deleterow ( 1 );
}
For ( VaR I = 0 ; I < This . Datasource. Length - 1 && I < This . Maxitems; I ++ )
{
This . _ Additem ( This . Datasource [I]);
}
}
},
_ Additem: Function (OBJ ){
VaR Table = $ Get ( This . Table );
VaR ID = OBJ. jobid;
VaR Name = OBJ. Name;
VaR Tr = Document. createelement ( " Tr " );
VaR TD = Document. createelement ( " TD " );
TD. classname = " TD " ;
TD. innertext = " · " ;
VaR A = Document. createelement ( " A " );
A. href = " Javascript: editjob (' " + ID + " ') " ;
A. innertext = Name;
TD. appendchild ();
Tr. appendchild (TD );
Table. firstchild. appendchild (TR );
},
Additem: Function (OBJ ){
VaR Table = $ Get ( This . Table );
This . _ Additem (OBJ );
Table. moverow (table. Rows. Length - 1 , 1 );
If (Table. Rows. Length - 1 > This . Maxitems)
Table. deleterow (table. Rows. Length - 1 );
}
}
VaRList=NewDatalist ();
List. Table="Table1";
</SCRIPT>
Then, register a JS script on the server to call the additem () method of the list.
VaR Newjob = { " Jobid " : 12 , " Name " : " Asdasfd " };
This . Parent. List. additem (newjob );
We mainly design operations on tables in the Dom, such as moving rows and deleting rows. It can be used for reference in future projects.
Recently, a buddy used JavaScript to write a browser-like control, such as the gridview, and cooperated with Ajax, which is very efficient and powerful.
I will study it first, and I will post it for you to study.