欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS中表單的使用小結(jié)

 更新時間:2014年01月11日 10:39:34   作者:  
本篇文章主要是對JS中表單的使用進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助

1.javascript刷新頁面的方法
     
window.location.reload();

使用window.open()彈出的彈出窗口,刷新父窗口
    window.opener.location.reload()

使用window.showDialog彈出的模式窗口
    window.dialogArguments.location.reload();

2.javascript彈出窗口的兩種實現(xiàn)方式 ---下面給兩個彈出屏幕居中窗口的例子
window.open()方式

復(fù)制代碼 代碼如下:

       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方式
復(fù)制代碼 代碼如下:

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

注意這里的第二個參數(shù),window

3.頁面中設(shè)置不進(jìn)行緩存數(shù)據(jù)的方法

在jsp頁面加入如下語句 

復(fù)制代碼 代碼如下:

<%
      response.setHeader("Pragma","No-Cache");
      response.setHeader("Cache-Control","No-Cache");
      response.setDateHeader("Expires", 0);
%>

4.無提示關(guān)閉頁面的方法
復(fù)制代碼 代碼如下:

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、定時關(guān)閉彈出的窗口---設(shè)置/清除定時器
復(fù)制代碼 代碼如下:

scriptlanguage="JavaScript"
!--
functioncloseit(){
setTimeout("self.close()",100000)//單位是毫秒,這里是100秒
setInterval("self.close()",100000)

window.clearTimeout(me.timer);
window.clearInterval(me.timer);
/script


6.javascript彈出子窗口中傳值---通過url傳值
復(fù)制代碼 代碼如下:

<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:;dialogTop:;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('這是值')">單擊</a>


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;//有效

設(shè)置/獲取元素的值
document.getElementById("labTitle").innerHTML="IP模式";//設(shè)置值
document.getElementById("labTitle").innerHTML//獲取值
labTitle 為div,span,table的id

實例1:

復(fù)制代碼 代碼如下:
<input id="mytext" type="text" value="我是不能用的">
<input type="button" value="disabled" onClick="javascript: document.all.mytext.disabled='false'">
<input type="button" value="enable" onClick="javascript: document.all.mytext.removeAttribute('disabled')">

實例2:

復(fù)制代碼 代碼如下:
<input id="mytext" type="text" value="我是能用的">
<input type="button" value="disable" onClick="if (mytext.disabled==false){ mytext.disabled=true;mytext.value='我是不能用的';this.value='enable'} else { mytext.disabled=false;mytext.value='我是能用的';this.value='disable'}">

9.頁面通過函數(shù)提交表單的方法

復(fù)制代碼 代碼如下:

function exit(){
selcardForm.action="/NDHotel/queryTroom.do?method=exitSystem";
selcardForm.submit();
}

10.遍歷radio方法
復(fù)制代碼 代碼如下:

<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.向select中動態(tài)添加option
復(fù)制代碼 代碼如下:

<select id="ddlProvince" name="ddlProvince" onchange="cityResult()">

var prov=document.getElementById("ddlProvince");
        prov.options.add(new Option("---請選擇---",""));
    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.頁面中使用prototype ajax提交數(shù)據(jù)的實現(xiàn)方式(java)

一步:在<head></head>中添加以下js文件鏈接

復(fù)制代碼 代碼如下:

<head>
<script language="JavaScript" src="/NDHotel/js/prototype-1.6.js"></script>
</head>

二步:把prototype-1.6.js文件放到/NDHotel/js/指定的目錄中

三步:在<script type="text/javascript"></script>中聲明以下調(diào)用函數(shù)

復(fù)制代碼 代碼如下:

<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;
    if(returnStr =='fail'){
      alert("");
      return false; 
    }
}
</script>


四步:實現(xiàn)后臺調(diào)用
復(fù)制代碼 代碼如下:

 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中獲取表單的值的方式:
復(fù)制代碼 代碼如下:
document.getElementById("lindex").value
document.all.lindex.value//lindex在頁面中必須是唯一的

//設(shè)置獲取焦點
document.getElementById("lindex").focus()
document.all.startip.focus()

//設(shè)置失去焦點
document.getElementById("lindex").blur()
document.all.startip.blur()


14.動態(tài)添加/刪除表格中的行
復(fù)制代碼 代碼如下:

<table width="100%"  id="tdSearch" name="tdSearch" cellpadding="0" cellspacing="0" align="center">
</table>

//動態(tài)生成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 = "<input width='200' value='"+value1+"' onchange='changeip("+autoId+")' type='text' id='bIPFrom_"+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 trRow = document.getElementById(rowId);
  //alert(trRow);
 //if(rowId!="row_0"){
  trRow.removeNode(true);
 //}
}


15. 集合
復(fù)制代碼 代碼如下:

//顯示導(dǎo)入進(jìn)度條
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.設(shè)置文本框只讀屬性/設(shè)置文本框的顏色/設(shè)置radio選中
復(fù)制代碼 代碼如下:

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

相關(guān)文章

  • 基于JavaScript+HTML5 實現(xiàn)打地鼠小游戲邏輯流程圖文詳解(附完整代碼)

    基于JavaScript+HTML5 實現(xiàn)打地鼠小游戲邏輯流程圖文詳解(附完整代碼)

    打地鼠小游戲大家都喜歡玩,本文是以html編寫的,并且使用HBulider軟件進(jìn)行編寫的,下面通過本文給大家分享基于JavaScript+HTML5 實現(xiàn)打地鼠小游戲邏輯流程圖文詳解,需要的朋友參考下吧
    2017-11-11
  • JavaScript運動框架 多物體任意值運動(三)

    JavaScript運動框架 多物體任意值運動(三)

    這篇文章主要為大家詳細(xì)介紹了JavaScript運動框架的第三部分,多物體任意值運動,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 最新評論