作者:j酱油 | 来源:互联网 | 2022-07-03 03:48
1.Javascript刷新页面的方法
window.location.reload();
使用window.open()弹出的弹出窗口,刷新父窗口
window.opener.location.reload()
使用window.showDialog弹出的模式窗口
window.dialogArguments.location.reload();
2.Javascript弹出窗口的两种实现方式 ---下面给两个弹出屏幕居中窗口的例子
window.open()方式
代码如下:
function ShowDialog(url) {
var iDetail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,
,,top="+iTop+",left="+iLeft);
}
window.showModalDialog方式
代码如下:
function ShowDialog(url) {
var idialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px;
dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:no");
}
注意这里的第二个参数,window
3.页面中设置不进行缓存数据的方法
在jsp页面加入如下语句
代码如下:
<%
response.setHeader("Pragma","No-Cache");
response.setHeader("Cache-Control","No-Cache");
response.setDateHeader("Expires", 0);
%>
4.无提示关闭页面的方法
代码如下:
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、定时关闭弹出的窗口---设置/清除定时器 代码如下:
scriptlanguage="Javascript"
!--
functioncloseit(){
setTimeout("self.close()",100000)//单位是毫秒,这里是100秒
setInterval("self.close()",100000)
window.clearTimeout(me.timer);
window.clearInterval(me.timer);
/script
6.Javascript弹出子窗口中传值---通过url传值
代码如下:
二步:把prototype-1.6.js文件放到/NDHotel/js/指定的目录中
三步:在中声明以下调用函数
代码如下:
四步:实现后台调用
代码如下:
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中获取表单的值的方式:
代码如下:
document.getElementById("lindex").value
document.all.lindex.value//lindex在页面中必须是唯一的
//设置获取焦点
document.getElementById("lindex").focus()
document.all.startip.focus()
//设置失去焦点
document.getElementById("lindex").blur()
document.all.startip.blur()
14.动态添加/删除表格中的行 代码如下:
15. 集合
代码如下:
//显示导入进度条
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.新建一个窗口
function layer1AddGroup() {
var url='/NDHotel/jsp/systemset/roomSet/addGroup.jsp';
var newwin=window.showModalDialog(url,window,"dialog);
}
//刷新父页面
function roomMainLeftRightFrame(){
var layer='<%=layer%>';
window.parent.parent.frames('view').location.href="/NDHotel/troom.do?method=roomSetLeftMenu&layer="+layer;
}
17.设置文本框只读属性/设置文本框的颜色/设置radio选中 代码如下:
document.all("txt_AutoTime").readOnly=true;
document.all("txt_AutoTime").style.backgroundColor="#d0d0d0";
runParamSetForm.radNotForcibly.checked=true;
//IP地址验证
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;
}