最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

JS中表单的使用小结_javascript技巧

来源:动视网 责编:小采 时间:2020-11-27 21:18:31
文档

JS中表单的使用小结_javascript技巧

JS中表单的使用小结_javascript技巧:1.javascript刷新页面的方法 window.location.reload();使用window.open()弹出的弹出窗口,刷新父窗口 window.opener.location.reload() 使用window.showDialog弹出的模式窗口 window.dialogArguments.location.re
推荐度:
导读JS中表单的使用小结_javascript技巧:1.javascript刷新页面的方法 window.location.reload();使用window.open()弹出的弹出窗口,刷新父窗口 window.opener.location.reload() 使用window.showDialog弹出的模式窗口 window.dialogArguments.location.re


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 iWidth=300; //窗口宽度
var iHeight=200;//窗口高度
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方式
代码如下:
function ShowDialog(url) {
var iWidth=300; //窗口宽度
var iHeight=200;//窗口高度
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");
}

注意这里的第二个参数,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传值
代码如下:

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";}

单击

7.js隐藏/显示表单
document.all("id").style.display=="none";//隐藏
document.all("id").style.display=="";//显示
document.getElementById("bt").style.display=="none"
document.getElementById("bt").style.display==""
id为table,input 的id

8.js控制表单元素有效/失效
document.getElementById("bt").disabled=true;
document.all("Submit1").disabled=true;//失效
document.all("Submit1").disabled=false;//有效

设置/获取元素的值
document.getElementById("labTitle").innerHTML="IP模式";//设置值
document.getElementById("labTitle").innerHTML//获取值
labTitle 为div,span,table的id

实例1:
代码如下:

实例2:
代码如下:

9.页面通过函数提交表单的方法
代码如下:
function exit(){
selcardForm.action="/NDHotel/queryTroom.do?method=exitSystem";
selcardForm.submit();
}

10.遍历radio方法
代码如下:

var radios=document.getElementsByName("workMode");
var workMode="";
for(var i=0;i if(radios[i].checked==true){
workMode=radios[i].value;
}
}

11.向select中动态添加option
代码如下:
-";

newRow.insertCell();
newRow.cells[1].innerHTML = " ";

var cell2 = newRow.insertCell();
cell2.innerHTML = "";
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. 集合
代码如下:
//显示导入进度条
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,"dialogWidth=470px;dialogHeight=400px;scroll=yes;status=no;help=no;");
}

//刷新父页面
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;
}

文档

JS中表单的使用小结_javascript技巧

JS中表单的使用小结_javascript技巧:1.javascript刷新页面的方法 window.location.reload();使用window.open()弹出的弹出窗口,刷新父窗口 window.opener.location.reload() 使用window.showDialog弹出的模式窗口 window.dialogArguments.location.re
推荐度:
标签: js 表单 javascript
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top