为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

It's keydown event "event.preventDefault()" not worked when i used XMLHttpRequest object with synchronal request.

  • 1 个回答
  • 14 人有此问题
  • 7 次查看
  • 最后回复者为 cash2910

more options

dear all. by the question title, i want to disabled "Tab" key in one input field in HTML page, it's normal worked by :

=========HTML================

<input id="fy" value="" onkeydown="doKeydown(this,event)">

==============================
=========SCRIPT===============

<script> function doKeydown(obj,ev){

   if(ev.keyCode == 9){
      
      if (ev.preventDefault){
           ev.preventDefault();
           ev.stopPropagation();
      }
      
      ev.cancelBubble=true;
      
   }

} </script>

============================

but,when i add XMLHttpRequest with synchronal request in doKeydown function. it's can't worked....

====== <ALL HTML>=======

<meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>FF XMLHttpRequest</title> <script type="text/javascript"> function createXmlHttpObj(){ var _xmlHttp; try { _xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { _xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { _xmlHttp = null; } } if (_xmlHttp==null && typeof XMLHttpRequest != 'undefined') { _xmlHttp = new XMLHttpRequest(); } return _xmlHttp; } function transCompany_ajax_codeValue(codeObjAry,containerObjAry,fieldStrAry,ev) { var urlStr = "./test1.asp?transCompanyCode={arg0}"; ajax_codeValue1(codeObjAry ,containerObjAry ,fieldStrAry ,urlStr); } function ajax_codeValue1(codeObjAry,containerObjAry,fieldStrAry,urlStr,callbackFuncName) { var _async = document.getElementById("is_async").checked; for (i=0;i<codeObjAry.length;i++) { urlStr = urlStr.replace("{arg" + i + "}",codeObjAry[i].value); if (codeObjAry[i].value=="") { hasNotInputFlag = false; } } var xmlHttpObj = createXmlHttpObj(); //xmlHttpObj.async = _async; xmlHttpObj.open("get",urlStr, _async); xmlHttpObj.setRequestHeader("Content-Type", "text/xml"); //xmlHttpObj.setRequestHeader("X-Requested-With","XMLHttpRequest"); if(_async){ xmlHttpObj.onreadystatechange = function(){ //console.log("onReadyStateChange"); if (this.readyState == 4) { if (this.status == 200) { returnValueObj = eval("(" + this.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i] , eval("returnValueObj." + fieldStrAry[i])); } } //console.log("load success"); } else{ } } } ; } xmlHttpObj.send(); if(!_async){ var returnValueObj = eval("(" + xmlHttpObj.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i],eval("returnValueObj." + fieldStrAry[i])); } } } } function oncodeChange(){ var obj = document.getElementById("fy") ; var disObj = document.getElementById("uo"); var codeObjAry = new Array(); codeObjAry[0] = obj; var containerObjAry = new Array(); containerObjAry[0] = disObj; var filedAry = new Array(); filedAry[0] = "transCompanyName"; transCompany_ajax_codeValue(codeObjAry,containerObjAry,filedAry); } function setObjShow(obj,showValue) { //when is cell object try{ obj.setValue(showValue?showValue:""); return; }catch(e){ } if (obj.tagName == "INPUT") { obj.value = showValue?showValue:""; } else { obj.innerHTML = showValue?showValue:""; } } function doKeydown(obj,ev){ if(ev.keyCode == 9){ oncodeChange(); if (ev.preventDefault){ ev.preventDefault(); ev.stopPropagation(); } ev.cancelBubble=true; } } </script> async: <input type="checkbox" id="is_async">
<input id="fy" value="" onkeydown="doKeydown(this,event)"> <input id="uo" value="" size="100">


====== </ALL HTML>=======

========<SERVER PAGE USE ASP>===========

<%@ Language=VBScript %> <%response.charset="utf-8"%> <% if trim(request.queryString("transCompanyCode"))="" then

   response.write "{""transCompanyName"":""Can not get name"",""transCompanyCode"":""""}"
   response.end

end if

response.write "{""transCompanyName"":""Name " & trim(request.queryString("transCompanyCode")) &""",""transCompanyCode"":""a""}" %> ========</SERVER PAGE>===========

dear all. by the question title, i want to disabled "Tab" key in one input field in HTML page, it's normal worked by : ===============HTML====================== <input id="fy" value="" onkeydown="doKeydown(this,event)"> ========================================== ===============SCRIPT===================== <script> function doKeydown(obj,ev){ if(ev.keyCode == 9){ if (ev.preventDefault){ ev.preventDefault(); ev.stopPropagation(); } ev.cancelBubble=true; } } </script> ======================================== but,when i add XMLHttpRequest with synchronal request in doKeydown function. it's can't worked.... '''====== <ALL HTML>=======''' <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> <title>FF XMLHttpRequest</title> <script type="text/javascript"> function createXmlHttpObj(){ var _xmlHttp; try { _xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { _xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { _xmlHttp = null; } } if (_xmlHttp==null && typeof XMLHttpRequest != 'undefined') { _xmlHttp = new XMLHttpRequest(); } return _xmlHttp; } function transCompany_ajax_codeValue(codeObjAry,containerObjAry,fieldStrAry,ev) { var urlStr = "./test1.asp?transCompanyCode={arg0}"; ajax_codeValue1(codeObjAry ,containerObjAry ,fieldStrAry ,urlStr); } function ajax_codeValue1(codeObjAry,containerObjAry,fieldStrAry,urlStr,callbackFuncName) { var _async = document.getElementById("is_async").checked; for (i=0;i<codeObjAry.length;i++) { urlStr = urlStr.replace("{arg" + i + "}",codeObjAry[i].value); if (codeObjAry[i].value=="") { hasNotInputFlag = false; } } var xmlHttpObj = createXmlHttpObj(); //xmlHttpObj.async = _async; xmlHttpObj.open("get",urlStr, _async); xmlHttpObj.setRequestHeader("Content-Type", "text/xml"); //xmlHttpObj.setRequestHeader("X-Requested-With","XMLHttpRequest"); if(_async){ xmlHttpObj.onreadystatechange = function(){ //console.log("onReadyStateChange"); if (this.readyState == 4) { if (this.status == 200) { returnValueObj = eval("(" + this.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i] , eval("returnValueObj." + fieldStrAry[i])); } } //console.log("load success"); } else{ } } } ; } xmlHttpObj.send(); if(!_async){ var returnValueObj = eval("(" + xmlHttpObj.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i],eval("returnValueObj." + fieldStrAry[i])); } } } } function oncodeChange(){ var obj = document.getElementById("fy") ; var disObj = document.getElementById("uo"); var codeObjAry = new Array(); codeObjAry[0] = obj; var containerObjAry = new Array(); containerObjAry[0] = disObj; var filedAry = new Array(); filedAry[0] = "transCompanyName"; transCompany_ajax_codeValue(codeObjAry,containerObjAry,filedAry); } function setObjShow(obj,showValue) { //when is cell object try{ obj.setValue(showValue?showValue:""); return; }catch(e){ } if (obj.tagName == "INPUT") { obj.value = showValue?showValue:""; } else { obj.innerHTML = showValue?showValue:""; } } function doKeydown(obj,ev){ if(ev.keyCode == 9){ oncodeChange(); if (ev.preventDefault){ ev.preventDefault(); ev.stopPropagation(); } ev.cancelBubble=true; } } </script> </head> <body> async: <input type="checkbox" id="is_async"> <br> <input id="fy" value="" onkeydown="doKeydown(this,event)"> <input id="uo" value="" size="100" > </body> </html> '''====== </ALL HTML>=======''' '''========<SERVER PAGE USE ASP>===========''' <%@ Language=VBScript %> <%response.charset="utf-8"%> <% if trim(request.queryString("transCompanyCode"))="" then response.write "{""transCompanyName"":""Can not get name"",""transCompanyCode"":""""}" response.end end if response.write "{""transCompanyName"":""Name " & trim(request.queryString("transCompanyCode")) &""",""transCompanyCode"":""a""}" %> '''========</SERVER PAGE>==========='''

由parsec于修改

所有回复 (1)

more options

check your other js code ...