1. How to refresh the page with javascript
Window. location. reload ();
Use window. open () to refresh the parent window.
Window. opener. location. reload ()
Window. showDialog
Window. dialogArguments. location. reload ();
2. Two implementation methods for the javascript pop-up window-the following example shows two pop-up screen center windows.
Window. open () method
Copy codeThe Code is as follows:
Function ShowDialog (url ){
Var iWidth = 300; // window width
Var iHeight = 200; // window height
Var iTop = (window. screen. height-iHeight)/2;
Var iLeft = (window. screen. width-iWidth)/2;
Window. open (url, "Detail", "Scrollbars = no, Toolbar = no, Location = no, Direction = no, Resizeable = no,
Width = "+ iWidth +", Height = "+ iHeight +", top = "+ iTop +", left = "+ iLeft );
}
Window. showModalDialog Mode
Copy codeThe Code is as follows:
Function ShowDialog (url ){
Var iWidth = 300; // window width
Var iHeight = 200; // window height
Var iTop = (window. screen. height-iHeight)/2;
Var iLeft = (window. screen. width-iWidth)/2;
Window. showModalDialog (url, window, "dialogHeight:" + iHeight + "px; dialogWidth:" + iWidth + "px;
DialogTop: "+ iTop +"; dialogLeft: "+ iLeft +"; resizable: no; status: no; scroll: no ");
}
Note that the second parameter here is window
3. Set the method for not caching data on the page
Add the following statement to the jsp page:
Copy codeThe Code is as follows:
<%
Response. setHeader ("Pragma", "No-Cache ");
Response. setHeader ("Cache-Control", "No-Cache ");
Response. setDateHeader ("Expires", 0 );
%>
4. There is no prompt to close the page.
Copy codeThe Code is as follows:
Function CloseWin (){
Var ua = navigator. userAgent; var ie = navigator. appName = "Microsoft Internet Explorer "? True: false;
If (ie ){
Var IEversion = parseFloat (ua. substring (ua. indexOf ("MSIE") + 5, ua. indexOf (";", ua. indexOf ("MSIE "))));
If (IEversion <5.5 ){
Var str = '';
Document. body. insertAdjacentHTML ("beforeEnd", str );
Document. all. noTipClose. Click ();
} Else {
Window. opener = null; window. close ();
}
} Else {
Window. close ()
}
}
5. Close the pop-up window regularly --- set/clear the timer
Copy codeThe Code is as follows:
Scriptlanguage = "JavaScript"
! --
Functioncloseit (){
SetTimeout ("self. close ()", 100000) // The unit is millisecond. The unit is 100 seconds.
SetInterval ("self. close ()", 100000)
Window. clearTimeout (me. timer );
Window. clearInterval (me. timer );
/Script
6. In the javascript pop-up window, pass the value through url.
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
Function fn_modify (pid ){
Var ModifyInfo = new Object ();
Window. showModalDialog ("modify_main.asp? Pid = "+ pid, ModifyInfo," dialogHeight: 180px; dialogWidth: 300px; dialogLeft:; dialogTop:; resizable: off; center: on; help: off; scroll: off; status: off ")
Reload ();
}
Function Reload () {location. href = "abc. asp ";}
</SCRIPT>
<A href = "abc. asp" onClick = "fn_modify ('this is the value')"> click </a>
7. js hide/display forms
Document. all ("id"). style. display = "none"; // hide
Document. all ("id"). style. display = ""; // display
Document. getElementById ("bt"). style. display = "none"
Document. getElementById ("bt"). style. display = ""
Id: table, input id
8. js control form elements are valid/invalid
Document. getElementById ("bt"). disabled = true;
Document. all ("Submit1"). disabled = true; // invalid
Document. all ("Submit1"). disabled = false; // valid
Set/obtain element values
Document. getElementById ("labTitle"). innerHTML = "IP Mode"; // set the value
Document. getElementById ("labTitle"). innerHTML // get the value
LabTitle is the id of div, span, and table.
Instance 1:
Copy codeThe Code is as follows: <input id = "mytext" type = "text" value = "I cannot use">
<Input type = "button" value = "disabled" onClick = "javascript: document. all. mytext. disabled = 'false'">
<Input type = "button" value = "enable" onClick = "javascript: document. all. mytext. removeAttribute ('Disabled ')">
Instance 2:
Copy codeThe Code is as follows: <input id = "mytext" type = "text" value = "I can use">
<Input type = "button" value = "disable" onClick = "if (mytext. disabled = false) {mytext. disabled = true; mytext. value = 'I cannot use'; this. value = 'enable'} else {mytext. disabled = false; mytext. value = 'I can use it'; this. value = 'disable'} ">
9. How to submit a form through function on the page
Copy codeThe Code is as follows:
Function exit (){
SelcardForm. action = "/NDHotel/queryTroom. do? Method = exitSystem ";
SelcardForm. submit ();
}
10. traverse the radio Method
Copy codeThe Code is as follows:
<Input id = "mode1" type = "radio" name = "workMode" value = "1" checked>
Var radios = document. getElementsByName ("workMode ");
Var workMode = "";
For (var I = 0; I <radios. length; I ++ ){
If (radios [I]. checked = true ){
WorkMode = radios [I]. value;
}
}
11. dynamically add option to select
Copy codeThe Code is as follows:
<Select id = "ddlProvince" name = "ddlProvince" onchange = "cityResult ()">
Var prov = document. getElementById ("ddlProvince ");
Prov. options. add (new Option ("--- Select ---",""));
Var pArray = zoneIdProvince. split ("&");
For (var I = 0; I <pArray. length; I ++ ){
Var idpArray = pArray [I]. split ("#");
Var sZoneID = idpArray [0];
Var sProvince = idpArray [1];
Prov. options. add (new Option (sProvince, sZoneID ));
}
12. How to submit data using prototype ajax on the page (java)
Step 1: Add the following js File Link in Copy codeThe Code is as follows:
<Head>
<Script language = "JavaScript" src = "/NDHotel/js/prototype-1.6.js"> </script>
</Head>
Step 2: Put the prototype-1.6.js file in the/NDHotel/js/specified directory
Step 3: declare the following call function in <script type = "text/javascript"> </script>
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function editi1_gment (){
Var url = '/NDHotel/ipsegmentset. do? Method = roomChangeNotice ';
Var pars = 'startip = '+ startip +' & endip = '+ endip +' & lindex = '+ lindex;
New Ajax. Request (url, {method: 'get', parameters: pars, asynchronous: false, onComplete: editResult });
}
Function editResult (result ){
Var returnStr = result. responseText;
If (returnStr = 'fail '){
Alert ("");
Return false;
}
}
</Script>
Step 4: Implement background call
Copy codeThe Code is as follows:
Public ActionForward roomChangeNotice (ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String result = "";
PrintWriter pw = RainPrintWriter. getPrintWriter (response );
Try {
NotifyServiceTwo. sendMessage (4, 0 );
Result = "success ";
} Catch (Exception e ){
Logger. error ("roomChangeNotice" + e );
}
Pw. write (result );
Pw. close ();
Return null;
}
13. js:
Copy codeThe Code is as follows: document. getElementById ("lindex"). value
Document. all. lindex. value // lindex must be unique on the page.
// Set the focus
Document. getElementById ("lindex"). focus ()
Document. all. startip. focus ()
// Set to lose focus
Document. getElementById ("lindex"). blur ()
Document. all. startip. blur ()
14. dynamically Add/delete rows in the table
Copy codeThe Code is as follows:
<Table width = "100%" id = "tdSearch" name = "tdSearch" cellpadding = "0" cellspacing = "0" align = "center">
</Table>
// Dynamically generate table rows
Var autoId = 0; // auto-incrementing variable
Function addRow (value1, value2 ){
Var highQuery = document. getElementById ("tdSearch ");
HighQuery. insertRow ();
Var newRow = highQuery. rows [highQuery. rows. length-1];
NewRow. id = "row _" + autoId;
NewRow. insertCell ();
NewRow. cells [0]. innerHTML = "<input width = '000000' value = '" + value1 + "'onchange = 'changeip (" + autoId + ") 'Type = 'text' id = 'bipfrom _ "+ autoId +" '> -";
NewRow. insertCell ();
NewRow. cells [1]. innerHTML = "<input width = '000000' value = '" + value2 + "'Type = 'text' id = 'to to _" + autoId + "'> ";
Var cell2 = newRow. insertCell ();
Cell2.innerHTML = "<input class = 'btn _ 1word' type = 'button 'class = 'hq _ button' value ='-'onclick = removeRow ('" + newRow. id + "')> ";
Cell2.setAttribute ("class", "yellowCell2 ");
AutoId = autoId + 1;
}
Function removeRow (rowId ){
Var trRow = document. getElementById (rowId );
// Alert (trRow );
// If (rowId! = "Row_0 "){
TrRow. removeNode (true );
//}
}
15. Set
Copy codeThe Code is as follows:
// Display the import progress bar
Document. all ("btnImport"). disabled = true;
Document. all ("maid"). style. left = 100;
Document. all ("maid"). style. top = 295;
Document. all ("maid"). style. display = "";
Form1.action = "/NDHotel/jsp/systemset/roomSet/uploadFile. jsp ";
Form1.submit ();
16. Create a window
Function layer1AddGroup (){
Var url = '/NDHotel/jsp/systemset/roomSet/addGroup. js ';
Var newwin = window. showModalDialog (url, window, "dialogWidth = 470px; dialogHeight = 400px; scroll = yes; status = no; help = no ;");
}
// Refresh the parent page
Function roomMainLeftRightFrame (){
Var layer = '<% = layer %> ';
Window. parent. parent. frames ('view'). location. href = "/NDHotel/troom. do? Method = roomSetLeftMenu & layer = "+ layer;
}
17. Set the text box read-only attribute/set the color of the text box/set radio Selection
Copy codeThe Code is as follows:
Document. all ("txt_AutoTime"). readOnly = true;
Document. all ("txt_AutoTime"). style. backgroundColor = "# d0d0d0 ";
RunParamSetForm. radNotForcibly. checked = true;
// Ip address verification
Function ipCheck (ipValue ){
Var reg =/^/d {1, 3} (/./d {1, 3}) {3} $ /;
If (ipValue! = ""){
If (reg. test (ipValue )){
Var ary = ipValue. split ('.');
For (key in ary ){
If (parseInt (ary [key])> 255)
Return false;
}
Return true;
} Else
Return false;
} Else
Return true;
}