您现在的位置: Gufang > 博客 > 学无止境 > 正文
用javascritp脚本在页面中传递参数和接受参数的方法

<SCRIPT language="JavaScript">
   //根据向本页面传递的QueryString解析出父页面TextBox框的ID值,并获取
   function FillField()
   {      
    document.all('textfield').value  = window.opener.document.all(getUrlParam('displayfield')).value;
    if(getUrlParam('hidefield') !='')
    {     
     document.all('valuefield').value = window.opener.document.all(getUrlParam('hidefield')).value;               
    }    
   }   
  </SCRIPT>
  <script language="JavaScript"> 
  //负责解析QueryString
  function setUrlParam(url, param, v)
  {
   var re = new RegExp("(
///?|&)" + param + "=([^&]+)(&|$)", "i");
   var m = url.match(re);
   if (m)
   {
    return (url.replace(re, function($0, $1, $2) { return ($0.replace($2, v)); } ));
   }
   else
   {
    if (url.indexOf('?') == -1)
     return (url + '?' + param + '=' + v);
    else
     return (url + '&' + param + '=' + v);
   }
  }

  function getUrlParam(param)
  {
   url = window.document.location.href;   
   var re = new RegExp("(
///?|&)" + param + "=([^&]+)(&|$)", "i");
   var m = url.match(re);
   if (m)
    return m[2];
   else
    return '';
  } 
  </script> 
  
  <script language="javascript">
  //主动将本页面的值,传递到SessionDispatch.aspx页面中
   function showServerTime(displayfield,hidenfield)
   {
    var strA = "textarea="+document.all(displayfield).value+"&valuearea="+document.all(hidenfield).value; 
    var oReq = new ActiveXObject("MSXML2.XMLHTTP");
    oReq.open("POST","SessionDispatch.aspx",false);
    oReq.setRequestHeader("Content-Length",strA.length);  
    oReq.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
    oReq.send(URLEncoding(strA));
   }
  </script>
  
  <SCRIPT language="VBScript">
  //负责在传递的字符流中,传递中文字符
   Function URLEncoding(vstrIn)
       strReturn = ""
       For i = 1 To Len(vstrIn)
           ThisChr = Mid(vStrIn,i,1)
           If Abs(Asc(ThisChr)) < &HFF Then
               strReturn = strReturn & ThisChr
           Else
               innerCode = Asc(ThisChr)
               If innerCode < 0 Then
                   innerCode = innerCode + &H10000
               End If
               Hight8 = (innerCode  And &HFF00)/ &HFF
               Low8 = innerCode And &HFF
               strReturn = strReturn & "%" & Hex(Hight8) &  "%" & Hex(Low8)
           End If
       Next
       URLEncoding = strReturn
   End Function
   
   Function bytes2BSTR(vIn)
       strReturn = ""
       For i = 1 To LenB(vIn)
           ThisCharCode = AscB(MidB(vIn,i,1))
           If ThisCharCode < &H80 Then
               strReturn = strReturn & Chr(ThisCharCode)
           Else
               NextCharCode = AscB(MidB(vIn,i+1,1))
               strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
               i = i + 1
           End If
       Next
       bytes2BSTR = strReturn
   End Function 
  </SCRIPT>
  
  //在后台中调用前台方法
  this.Button1.Attributes["onclick"] = "showServerTime('TB_Display','TB_Hide')";

or

   this.CmdSave.Attributes.Add("OnFocus","return isCompare();");
  //也可在前台中如此调用
  <form name="form1" method="post" action="default.asp" target="_blank"> <input type="submit" name="Submit" value="我要在线支付" onClick="javascript:document.form1.submit();"></from>

发表评论(0)
姓名 *
电子邮件
QQ
评论内容 *
验证问题 * 江苏省的省会是哪个城市?请填写正确答案
验证码 *图片看不清?点击重新得到验证码