JS表单使用总结

  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页面加入如下语句
  
  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
  function fn_modify(pid){
  var ModifyInfo=new Object();
  window.showModalDialog("modify_main.asp?pid="+pid, ModifyInfo,"dialogHeight:180px;dialogWidth:300px;di alogLeft:;dialogTop:;resizable:off;center:on;help:o ff;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:
  [code]
  
  [/ code]
  实例2:
  [code]
   [/code]
  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
  var prov=document.getElementById("ddlProvince");
  prov.options.add(new Option("---请选择---",""));
  var pArray=zoneIdProvince.split("&");
  for(var i=0;i中添加以下js文件链接
  
  
  
  二步:把prototype-1.6.js文件放到/NDHotel/js/指定的目录中
  三步:在中声明以下调用函数
  
  function editIpSegment(){
  var url='/NDHotel/ipsegmentset.do?method=roomChangeNot ice';
  var pars = 'startip='+startip+'&endip='+endip+'&lindex='+lind ex;
  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;
  }
  }
  
  四步:实现后台调用
  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.动态添加/删除表格中的行
  
  
  //动态生成table的行
  var autoId = 0; // 自增变量
  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 = "-";
  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/uploa dFile.jsp";
  form1.submit();
  13.新建一个窗口
  function layer1AddGroup() {
  var url='/NDHotel/jsp/systemset/roomSet/addGroup.jsp';
  var newwin=window.showModalDialog(url,window,"dialogWi dth=470px;dialogHeight=400px;scroll=yes;status=no;h elp=no;");
  }
  //刷新父页面
  function roomMainLeftRightFrame(){
  var layer='';
  window.parent.parent.frames('view').location.href= "/NDHotel/troom.do?method=roomSetLeftMenu&layer="+l ayer;
  }
  14.设置文本框只读属性/设置文本框的颜色/设置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;
  }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值