0

按下回车键时如何获取内容?

<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Mode) {
 HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
 HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
 HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
         }
      } 

     if (!HttPRequest) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      var url = 're.asp';
      var pmeters = "lname=" + encodeURI( document.getElementById("txtCustomerID").value) +
                    "&tMode=" + Mode;

        HttPRequest.open('POST',url,true);

        HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        HttPRequest.setRequestHeader("Content-length", pmeters.length);
        HttPRequest.send(pmeters);


        HttPRequest.onreadystatechange = function()
        {

             if(HttPRequest.readyState == 3)  // Loading Request
              {
               document.getElementById("mySpan").innerHTML = "Now is Loading...";
              }

             if(HttPRequest.readyState == 4) // Return Request
              {
               document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
               document.getElementById("txtCustomerID").value = '';
              }

        }

   }
</script>

 <form name="frmMain"action="#">
 <textarea name="txtCustomerID" id="txtCustomerID"onkeydown="if (event.keyCode == 13) { this.form.submit(); return false; }"></textarea>


**> how to get content when enter form keyboard (enter submit function)**

 <input type="button" name="btnAdd" id="btnAdd" value="Add"OnClick="JavaScript:doCallAjax('ADD');">

 <span id="mySpan"></span>
 </form>
4

1 回答 1

1

在服务器端,您可以使用 Request 对象获取值。例如:

<%
Dim serverTxtCustomerID
serverTxtCustomerID = Request("lname")
%>

您可以在此处阅读有关 Request 对象的更多信息。

于 2013-05-16T04:22:20.197 回答