×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

not really, this one is better

<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM>
TextArea tab test<BR><BR>
<TEXTAREA VALUE="" NAME="BOX_A" ROWS=15 COLS=39 onkeydown = "return handleTab(event)"></TEXTAREA>
</FORM>
<SCRIPT type="text/javascript">
function handleTab(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode == 9)
{
if (document.selection != null)
{

document.selection.createRange().text = "\ x 0 9"; //remove the space when
}
else
{
evt.srcElement.value += "\ x 0 9"; //remove the space when
return false;
}
return false;
}
return true
}
</SCRIPT>
</BODY>
</HTML>
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / 各位大虾春节好,请问如何使TEXTAREA支持TAB键?
    • 大虾春节好, Shift+Tab
      • 试过了,好象无反映啊!
    • use JavaScript
      • How to ? Thanks...
    • I don't understand ur question, TextArea automatecly support Tab key, could u tell us what result do u want to get?
      • TEXTAREA中使用TAB时,会跳转到同页面中下一个对象,而不是在TEXTAREA中对应内容进格。如果按SHIFT+TAB,将会跳转到同一页面前一个对象。如果按CTRL+TAB会跳转到下一个FRAME。如何让其在TEXTAREA中进格?
        • try onkeydown event
          <HTML>
          <HEAD>
          </HEAD>
          <BODY>
          <FORM>
          TextArea tab test<BR><BR>
          <TEXTAREA VALUE="" NAME="BOX_A" ROWS=15 COLS=39 onkeydown = "return handleTab(event)"></TEXTAREA>
          </FORM>
          <SCRIPT type="text/javascript">
          function handleTab(evt)
          {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode == 9)
          {
          document.forms[0].BOX_A.value += "\ x 0 9"; //remove the space when you try.
          return false;
          }
          return true
          }
          </SCRIPT>
          </BODY>
          </HTML>
          • Sorry, sir, it's my fault, ur codes works very well
            • not really, this one is better
              <HTML>
              <HEAD>
              </HEAD>
              <BODY>
              <FORM>
              TextArea tab test<BR><BR>
              <TEXTAREA VALUE="" NAME="BOX_A" ROWS=15 COLS=39 onkeydown = "return handleTab(event)"></TEXTAREA>
              </FORM>
              <SCRIPT type="text/javascript">
              function handleTab(evt)
              {
              var charCode = (evt.which) ? evt.which : event.keyCode;
              if (charCode == 9)
              {
              if (document.selection != null)
              {

              document.selection.createRange().text = "\ x 0 9"; //remove the space when
              }
              else
              {
              evt.srcElement.value += "\ x 0 9"; //remove the space when
              return false;
              }
              return false;
              }
              return true
              }
              </SCRIPT>
              </BODY>
              </HTML>
            • Yeah, execellent, that is the best result I want, hehe, I forgot how to create TextRange, U r great, thanks
          • 非常感谢,但还有个问题,当通过鼠标选取了一个区域后,再按TAB键,就无法把这个区域内容一齐向后移动了,大虾有解决方案吗?
        • No, buddy, U have to set the focus back to the TextArea, this is my version, still not very good, I think if we want to get the best result just like Win Form, we have to use TextRange and more JScript codes......
          <html>

          <script type="text/javascript">
          function change()
          {
          x=document.all.DropDownList1.value;
          if(x=="x4")
          eval("document.all.Text1.style.visibility='hidden';");
          else
          eval("document.all.Text1.style.visibility='visible';");
          }

          function keydown()
          {
          if(event.keyCode=='9')
          {
          document.all.DropDownList1.focus();
          document.all.TextBox1.value += "\x09";
          }
          }
          </script>
          <body>
          <form name="form1" method="post" id="form1">
          <select name="DropDownList1" id="DropDownList1" onchange="change()">
          <option value="x1">x1</option>
          <option value="x2">x2</option>
          <option value="x3">x3</option>
          <option value="x4">x4</option>
          </select>

          <textarea name="TextBox1" rows="2" cols="20" id="TextBox1" onkeydown="keydown()" style="height:126px;"></textarea>

          <input id="Text1" type="text" value="cctv"/>
          </form1>
          </body>
          </html>