按TAB键在同一页/不同页面上显示文本框值

时间:2012-02-09 12:34:36

标签: javascript jquery ajax jsp

我有一个文本框,当我在该文本框上写一些内容时,如果按下TAB键,则会发出警告“请等待”,然后我想在该jsp页面或不同的jsp页面中显示输入的值,警报即将到来,但未显示输入的文本框值,如何完成?

// a.jsp

<script type="text/javascript">
 var obj;
  var TAB = 9;
  function catchTAB(evt,elem)
  {
   obj = elem;
   var keyCode;
   if ("which" in evt)
    {// NN4 & FF &amp; Opera
     keyCode=evt.which;
   } else if ("keyCode" in evt)
    {// Safari & IE4+
  keyCode=evt.keyCode;
 } else if ("keyCode" in window.event)
 {// IE4+
keyCode=window.event.keyCode;
} else if ("which" in window.event)
{
 keyCode=evt.which;
} else  {    alert("the browser don't support");  }

 if (keyCode == TAB)
 {
 obj.value = obj.value + "\t";
 alert("Please wait");
 setTimeout("obj.focus()",1);// the focus is set back to the text input
}
}
</script>
<body>
 <input type="text" name="textboxname" onkeydown="catchTAB(event,this);"/>// after hitting TAB key i want to see that entered value in a.jsp page, how can i do it?
</body>

任何帮助

1 个答案:

答案 0 :(得分:0)

由于您能够捕获Tab事件,因此很容易从该事件中获取值并将其填充到该页面的任何位置。

     <script type="text/javascript">
 var obj;
  var TAB = 9;
  function catchTAB(evt,elem)
  {
   obj = elem;
   var keyCode;
   if ("which" in evt)
    {// NN4 & FF &amp; Opera
     keyCode=evt.which;
   } else if ("keyCode" in evt)
    {// Safari & IE4+
  keyCode=evt.keyCode;
 } else if ("keyCode" in window.event)
 {// IE4+
keyCode=window.event.keyCode;
} else if ("which" in window.event)
{
 keyCode=evt.which;
} else  {    alert("the browser don't support");  }

 if (keyCode == TAB)
 {
 obj.value = obj.value + "\t";
 alert("Please wait");
alert( obj.value);
document.getElementById('textboxNew').value = obj.value;
 setTimeout("obj.focus()",1);// the focus is set back to the text input
}
}
</script>
<body>
 <input type="text" name="textboxname" onkeydown="catchTAB(event,this);"/>// after hitting TAB key i want to see that entered 

value in a.jsp page, how can i do it?

<input type="text" name="textboxNew" id="textboxNew"/>
</body>