Home  >  Article  >  Web Front-end  >  Two common ways to pop up a box in Js and return a value_javascript skills

Two common ways to pop up a box in Js and return a value_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:12:571392browse
1.window.showModalDialog(url,args,dialogattrs)
Parameter description:
url: Pop-up page address
agrs: Parameters passed from the main window to the dialog box, which can be of any type (Arrays are also available)
dialogattrs: style parameters of pop-up windows
Modal dialog usage:
Main window: var value =window.showModalDialog('test.jsp',strs,'resizable:yes') ;
Set the return value through window.returnValue in the pop-up box. The value above is the value obtained. Then the
value can be processed in the main window to achieve interactive processing
Note: Modal dialogue The application of the box lies in its return value, which can return simple characters or arrays. The modeless dialog box is similar to
2. window.open:
[Parent window]
Copy code The code is as follows:

<script> <br>function show_child() <br>{ <br>var child=window .open("child.html","child","height=200,width=400,status=yes, toolbar=no,menubar=no,location=no"); <br>/* if(!child.closed) <br>{ <br>if(!window .close()) <br>{ <br>var textValue = frm.txt.value; parent.frm0.txt0.value = textValue; <br>} <br>else <br>{ <br>window .close(); <br>child.close(); <br>} <br>}*/ <br>} <br></script>
Open child window
< ;form name=frm0>
//Note that the ID attribute must be written here, otherwise the value cannot be obtained in FF
< /form>

[Subwindow]
Copy code The code is as follows:

<script> <br>function choseItem() <br>{ <br>var v=""; <br>var check_item = document.frm.item; <br>for(i=0;i&lt ;check_item.length;i ) <br>{ <br>if(check_item[i].checked) <br>{ <br>v ="," check_item[i].value; <br>} <br>document .frm.txt.value=v.replace(/^,{1}/,""); <br>} <br>} <br>function foo() <br>{ <br>window .close() ; <br>window .opener.document.getElementById("txt0").value=document.getElementById("txt").value <br>} <br></script>


a
b
c
d





Summary: In general, windows.open is used because there are many customizations. There are many windows.open. Many of the above web page editors like to use showModalDialog. If you really don’t know which one to use, just use window.open. Many mature cms systems use window.open.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn