ArticleDirectory
- 1. Background
- 2 key code
- 3 demo
1. Background
When using an application system, you often need to pop up a page, select some data, and bring the data back to the parent page. There are usually the following situations:
- Select a single row record, assign the text to Textbox, and assign the number to hidden;
- Select a single row record, assign the text to Textbox, assign the number to Den den, and then refresh the page to the background;
- Select any multi-row record, assign the text (separated by commas) to Textbox, and assign the number (separated by commas) to hidden;
- Select the limit n rows of records, assign the text (separated by commas) to Textbox, and assign the number (separated by commas) to hidden;
In other cases, we need to provide a mechanism to support data transmission on Parent and Child pages. I divide it into two situations:
- Select a single row record and assign it to textbox and den automatically;
- Select (Single Row/any multiple rows/limit n rows), and then call your own method to assign values, refresh the page, or do other work.
2 key Code
Key code of the parent page:
View code
// Data is like [{key: 1, value: 1,...}, {key: 2, value: 2,...},...] VaR Targetcontrol = Null ; Function Singlecallback (data ){ If (Data. length> 0 ) {$ ( "# TXT" + targetcontrol). Val (data [0 ]. Value); $ ( "# HF" + targetcontrol). Val (data [0 ]. Key );} Else {$ ( "# TXT" + targetcontrol). Val (""); $ ( "# HF" + targetcontrol). Val ("" );}} VaR Comselect = { // General choice (automatically add the value to the text box and hidden Control) Selectsingle: Function (_ Title, _ URL, _ width, _ height, _ targetcontrol ){ VaR Param = "callfun = singlecallback & multi = false & hftargetid = Hf" + _ targetcontrol + "& limitnum = 1" ; _ URL. indexof ( "? ")> 0? _ URL + = "&" + Param: _ URL + = "? "+Param; targetcontrol = _ Targetcontrol; OpenWindow (_ URL, _ title, _ width, _ height )}, // Custom general selection, call user-specific methods Selectwithcallback: Function (_ Title, _ URL, _ width, _ height, _ callfun, _ targetcontrolid, _ limitnum ){ VaR Param = "callfun =" + _ callfun + "& multi = true & hftargetid =" + _ targetcontrolid + "& limitnum =" + _ Limitnum; _ URL. indexof ( "? ")> 0? _ URL + = "&" + Param: _ URL + = "? "+Param; OpenWindow (_ URL, _ title, _ width, _ height )}}
Parent page:
Key code displayed:
View code
$ (Document). Ready ( Function (){ // Load selected items Selecteddefault (); VaR Data = New Array (); $ ( ". Datatable tbody TR"). dblclick ( Function (){ // Select data for Organization Setcurrentvalue (data, 0, $ ( This )); // Call the parent page Method Callopenermethod (data) ;}); $ ( "# Btndone"). Click ( Function (){ VaR Checkarray = $ (": checked", $ (". datatable" )); // Limit the selected quantity VaR Limitnum = getquerystring ("limitnum" ); If (Limitnum! = "Undefined" & limitnum < Checkarray. Length) {alert ( "Select" + limitnum + "most! " ); Return ;} // Organize multiple selection data $. Each (checkarray, Function (Key, value) {setcurrentvalue (data, key, $ ( This ). Parents ("TR" ));}); // Call the parent page Method Callopenermethod (data )});});
Pop-up page:
3 demo
Demo download: Demo