1.javascript How to refresh the page
Window.location.reload ();
Use window.open () pop-up pop-up window to refresh the parent window
Window.opener.location.reload ()
Using the Window.showdialog pop-up mode window
Window.dialogArguments.location.reload ();
Two implementations of the 2.javascript pop-up window---The following example of a two pop-up screen centered window
window.open () way
Copy Code code 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 Way
Copy Code code 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 ");
}
Notice the second argument here, window
3. To set a method for not caching data in a page
Add the following statement to 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 ("BeforeEnd", str);
Document.all.noTipClose.Click ();
} else {
Window.opener =null; Window.close ();
}
}else{
Window.close ()
}
}
5, timed to close the pop-up window---set/clear Timer
Copy Code code as follows:
Scriptlanguage= "JavaScript"
!--
Functioncloseit () {
SetTimeout ("Self.close ()", 100000)//unit is milliseconds, this is 100 seconds
SetInterval ("Self.close ()", 100000)
Window.cleartimeout (Me.timer);
Window.clearinterval (Me.timer);
/script
6.javascript in Popup window---pass value through URL
Copy Code code 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: ;d Ialogtop:;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 value ')" > click </a>
7.js hide/Show form
document.all ("id"). style.display== "None";/hidden
document.all ("id"). style.display== ""/Show
document.getElementById ("BT"). style.display== "None"
document.getElementById ("BT"). style.display== ""
ID is table,input with ID
8.js control FORM element valid/invalid
document.getElementById ("BT"). Disabled=true;
document.all ("Submit1"). disabled=true;//failure
document.all ("Submit1"). disabled=false;//effective
Sets/Gets the value of an element
document.getElementById ("Labtitle"). Innerhtml= "IP mode";/Set Value
document.getElementById ("Labtitle"). innerhtml//Get Value
ID of Labtitle as div,span,table
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 am able to use" >
<input type= "button" value= "Disable" onclick= "if (mytext.disabled==false) {mytext.disabled=true;mytext.value= ' I am unable to use '; This.value= ' Enable '} else {mytext.disabled=false;mytext.value= ' I am able to use '; this.value= ' disable '} >
9. How a page submits a form through a function
Copy Code code as follows:
function exit () {
Selcardform.action= "/ndhotel/querytroom.do?method=exitsystem";
Selcardform.submit ();
}
10. Traversal 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. Dynamically add option to select
Copy Code code as follows:
<select id= "ddlprovince" name= "ddlprovince" onchange= "Cityresult ()" >
var Prov=document.getelementbyid ("Ddlprovince");
Prov.options.add ("---Please 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 use prototype Ajax to submit data in a page (Java)
One step: Add the following JS file link in
Copy Code code as follows:
<script language= "JavaScript" src= "/ndhotel/js/prototype-1.6.js" ></script>
Step two: Put the prototype-1.6.js file in the/ndhotel/js/specified directory
Three steps: Declare the following call function in the <script type= "Text/javascript" ></script>
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= ';
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>
Four step: Implement background call
Copy Code code 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;
}
How to obtain the value of the form in 13.js:
Copy Code code as follows:
document.getElementById ("Lindex"). Value
Document.all.lindex.value//lindex must be unique on the page
Set get focus
document.getElementById ("Lindex"). Focus ()
Document.all.startip.focus ()
Setting loses focus
document.getElementById ("Lindex"). Blur ()
Document.all.startip.blur ()
14. Dynamically Add/delete rows in a table
Copy Code code as follows:
<table width= "100%" id= "Tdsearch" name= "Tdsearch" cellpadding= "0" cellspacing= "0" align= "center" >
</table>
Dynamically generating rows for table
var autoid = 0; Self-increasing variables
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= ' value= '" +value1+ "' onchange= ' Changeip (" +autoid+ ") ' type= ' text ' id= ' Bipfrom_ ' +autoid+ ' >-';
Newrow.insertcell ();
newrow.cells[1].innerhtml = "<input width= ' 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 trrow = document.getElementById (rowId);
alert (Trrow);
if (rowid!= "Row_0") {
Trrow.removenode (TRUE);
//}
}
15. Collection
Copy Code code as follows:
Show Import 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;status=no;help=no ;");
}
Refreshing the parent page
function Roommainleftrightframe () {
var layer= ' <%=layer%> ';
Window.parent.parent.frames (' View '). location.href= "/ndhotel/troom.do?method=roomsetleftmenu&layer=" +layer;
}
17. Set text box read-only property/Set text box color/settings Radio selected
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;
}