1. How to refresh the page of JavaScript
Window.Location.Reload ();
Use Window.open () to pop up the pop -up window to refresh the father window
Window.opener.location.reload ()
Mode window pop -up using Window.showDialog
window.dialogarguments.location.reload ();
2. Two implementation methods of JavaScript pop-up window-the example of two pop-up screens in the middle window of the screen is given below
Window.open () method
Copy code code as follows:
Function ShowDialog (url) {
var IWIDTH = 300; // Wind 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, local = no, direction = no, resizeable = no,
Width = "+iwidth+", height = "+Iheight+", top = "+itop+", left = "+les);
}
Window.showmodalDialog method
Copy code code as follows:
Function ShowDialog (url) {
var IWIDTH = 300; // Wind 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 the second parameter here, Window
3. Method of setting the cache data in the page
Add the following statements on the jsp page
Copy code code as follows:
<%
response.Setheader ("Pragma", "No-Cache");
response.setHeader ("cache-control", "no-cache");
response.setdateheader ("Expires", 0);
%>
4. No prompt to close the page method
Copy code code 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 ("" beforend ", str);
document.all.notipClose.clICK ();
} Else {
window.opner = null; window.close ();
}
} Else {
window.close ()
}
}
5. Turn off the pop-up window-Set/Clear the timer
Copy code code as follows:
scriptLanguage = "javascript"
!--
FunctionCloseit () {
Settimeout ("Self.Close ()", 100000) // The unit is milliseconds, here is 100 seconds
Setinterval ("Self.close ()", 100000)
Window.Cleartimeout (me.timer);
Window.Clearinterval (me.timer);
/script
6. JavaScript pops up the sub-window in the sub-window --- via URL pass
Copy code code as follows:
<script language = "javascript" type = "text/javascript">
function fn_modify (PID) {
varmedifyinfo = 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" onclight = "fn_modify ('This is the value')"> Click </a>
7. JS Hidden/Display Form
document.all ("ID"). Style.display == "None"; // Hidden
document.all ("ID"). Style.display == "" ""; // Display
document.GetelementByid ("BT"). STYLE.DISPLAY == "None"
document.GetelementByid ("BT"). STYLE.DISPLAY == "" "" "" ""
ID is table, input ID
8. JS control form element is effective/failure
document.GetelementByid ("BT"). Disabled = true;
document.all ("submit1"). Disabled = true; //
document.all ("submit1"). Disabled = false; // Valid
Set/get the value of the element
document.GetelementByid ("Labtitle"). Innerhtml = "IP mode"; // Set the value
document.GetelementByid ("Labtitle"). Innerhtml // Get value
Labtitle is div, span, table ID
Example 1:
Copy code code as follows: <input ID = "MyText" Type = "Text" Value = "I can't use it">
<input type = "Button" Value = "Disabled" Onclick = "Javascript: Document.all.mytext.disabled = 'False'">
<input type = "Button" Value = "ENABLE" onClick = "Javascript: Document.all.mytext.removeattribute ('Disabled')"> ">
Example 2:
Copy code code as follows: <input ID = "MyText" Type = "Text" Value = "I can use it">
<input type = "Button" Value = "Disable" onClick = "IF (MyText.disabled == False) {MyText.disabled = True; . Value = 'ENABLE' } else {mytext.disabled = false; myText.value = 'I can use'; this.value = 'disable'} ">
9. The method of submitting the form by the page through the function
Copy code code as follows:
Function exit () {) {
selcardform.action = "/ndhotel/querytroom.do? Method = exitSystem";
selcardform.submit ();
}
10. Traversing RADIO method
Copy code code 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. Dynamic adding Option to Select
Copy code code as follows:
<select id = "ddlProvring" name = "ddlprovince" onchange = "cityresult ()">
var prov = document.GetelementByid ("DDLPROVINCE");
Prov.options.add (new option ("--- Please select ---", "");
var park = zoneidProvince.split ("&");
for (var I = 0; I <Parray.Length; I ++) {
var IDParray = Parray [i] .split ("#");
var szoneid = IDParray [0];
var Sprovring = IDParray [1];
Prov.options.add (New Option (SPROVINCE, Szoneid));
}
12. Page uses Prototype Ajax to submit data implementation (Java)
Step: Add the following JS file links in <head> </head>
Copy code code as follows:
<head>
<script language = "javascript" src = "/ndhotel/js/prototype -.6.js"> </script>
</head>
Step Two: Put the prototype -.6.js file in/ndhotel/js/specified directory
Step three: Declaration function is declared below
Copy code code as follows:
<script type = "text/javascript">
function editipsegment () {
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;
ifRnstr == 'Fail') {
alert ("");
Return false;
}
}
</script>
Four steps: realize background calls
Copy code code as follows:
Public Actionford 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. How to get the value of the form in JS:
Copy code code as follows: document.GetelementByid ("lindex"). Value
document.lindex.value // lindex must be the only one in the page
// Set the focus of acquisition
document.GetelementByid ("lindex"). Focus ()
document.all.startip.focus ()
// Set the lost focus
document.GetelementByid ("lindex"). Blur ()
document.all.startip.blur ()
14. Dynamic add/delete the line in the table
Copy code code as follows:
<Table ID = "tdsearch" name = "tdsearch" cellpadding = "0" cellspacing = "0" align = "center">
</table>
// Dynamically generate TABLE lines
var autoid = 0; // Self -increase 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 = '200' value = '"+value1+"' Onchange = 'Changeip ("+Autoid+")' Type = 'Text' ID = 'Bipfffffffff ROM _ "+Autoid+" ' >-";
newrow.insertcell ();
newrow.cells [1] .innerhtml = "<input width = '200' value = '"+value2+"' type = 'text' id = 'bipto _"+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 trow = document.GetelementByid (rowid);
// alert (trow);
// if (rowid! = "row_0") {
trow.removenode (true);
//}
}
15. Collection
Copy code code as follows:
// Display the introduction progress bar
document.all ("btnimport"). Disabled = true;
document.all ("datagrid_waitdiv"). STYLE.Left = 100;
document.all ("datagrid_waitdiv"). STYLE.TOP = 295;
document.all ("datagrid_waitdiv"). Style.display = "";
form1.ACTION = "//NDHotel/JSP/SystemSet/RoomSet/UploadFile.jsp";
form1.submit ();
16. Create a new window
function layer1addgroup () {
var url = '/ndhotel/jsp/systemSet/RoomSet/addgroup.jsp';
var newwin = window.showmodalDialog (url, window, "dialogwidth = 470px; dialogheight = 400px; scroll = yes; hardus = no;");
}
// Refresh the father 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 to read only the attribute/set the color of the text box/set the RADIO selection
Copy code code 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;
}