Client table operations

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.