+ -
当前位置:首页 → 问答吧 → jquery 取值问题!

jquery 取值问题!

时间:2011-12-07

来源:互联网

HTML code

$("input:text").each(function () {
            $(this).keyup(function () {
                if (event.keyCode == 13) {
                    var tt = $("form[name='why']").find(":text");
                    var idx = tt.index(this);
                    if (idx != tt.length - 1) {
                        tt[idx + 1].select();
                                                               
                    }
                }
            });

        });



上面的JQ是当按回车的时候下一个文本框获得焦点,但是我想获得的焦点在文本后面。网上有获取到文本框的值复制粘贴的方法做到,问题就在于tt[idx+1].val()报错。。 各位大哥帮忙

作者: bianchenga   发布时间: 2011-12-07

该回复于2011-12-07 17:28:01被管理员删除

  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
#2楼 得分:0回复于:2011-12-07 17:39:35
tt.index(this);
1、断点确定this是那个对象
2、idex值是否正确

作者: bianchenga   发布时间: 2011-12-07

按回车当前文本框后面的文本框获得焦点?

作者: jiuhexuan   发布时间: 2011-12-07

HTML code

 $(function() {
          $("input:text").keydown(function(event) {
              if (event.keyCode == "13") {

                  var tt = $("form[name='why']").find(":text");
                  $(this).next().focus();
              }
          });
      });


作者: Sandy945   发布时间: 2011-12-07

没理解。。

作者: a67251026   发布时间: 2011-12-07

该回复于2011-12-07 17:55:02被管理员删除

  • 对我有用[0]
  • 丢个板砖[0]
  • 引用
  • 举报
  • 管理
  • TOP
#7楼 得分:0回复于:2011-12-07 17:53:50
- - 前面看错了~


HTML code

<script>

      $(function() {
          $("input:text").keydown(function(event) {
              if (event.keyCode == "13") {

                  var tt = $("form[name='why']").find(":text");
                  $(this).next().focus();
                  $(this).next().selectRange(0, $(this).next().val().length);
                 
              }
          });
      });

      $.fn.selectRange = function(start, end) {
          return this.each(function() {
              if (this.setSelectionRange) {
                  this.focus();
                  this.setSelectionRange(start, end);
              } else if (this.createTextRange) {
                  var range = this.createTextRange();
                  range.collapse(true);
                  range.moveEnd('character', end);
                  range.moveStart('character', start);
                  range.select();
              }
          });
      };


  </script>



不过这个是选中全部。。。。。

作者: b327114069   发布时间: 2011-12-07

HTML code


 <script>

      $(function() {
          $("input:text").keydown(function(event) {
              if (event.keyCode == "13") {

                var tt = $("form[name='why']").find(":text");
                $(this).next().focusEnd();

              }
          });
      });

      $.fn.setCursorPosition = function(position) {
          if (this.lengh == 0) return this;
          return $(this).setSelection(position, position);
      }

      $.fn.setSelection = function(selectionStart, selectionEnd) {
          if (this.lengh == 0) return this;
          input = this[0];

          if (input.createTextRange) {
              var range = input.createTextRange();
              range.collapse(true);
              range.moveEnd('character', selectionEnd);
              range.moveStart('character', selectionStart);
              range.select();
          } else if (input.setSelectionRange) {
              input.focus();
              input.setSelectionRange(selectionStart, selectionEnd);
          }

          return this;
      }

      $.fn.focusEnd = function() {
          this.setCursorPosition(this.val().length);
      }


  </script>




这个可行~

作者: HIT_xiaobai   发布时间: 2011-12-07