简体   繁体   English

文本字段内的箭头键导航

[英]Arrow keys navigation within a text field

Arrow key (left and right) is not navigating within a text field. 箭头键(左右键)不在文本字段中导航。 Also placing a cursor within a text field and editing is not possible. 此外,无法将光标放在文本字段中并进行编辑。 Cursor jumps to the last every time I start adding a character. 每当我开始添加字符时,光标就会跳到最后一个。 It works fine in firefox but not working in Chrome and IE. 它在Firefox中工作正常,但在Chrome和IE中不起作用。 Code is as below. 代码如下。

$('#idname').bind('keyup blur', function(){ 
  $(this).val( $(this).val().replace(/[^a-z A-Z 0-9]/g,'') ); 
});

Am using jquery version 1.3. 我正在使用jquery 1.3版。

You should wrap the parameter in val() width a function like in this fiddle http://jsfiddle.net/robbiebardijn/Z4p48/ 您应该将参数包装在val()宽度中,像下面这样的小提琴一样: http://jsfiddle.net/robbiebardijn/Z4p48/

    $(this).val( function(){ 
      $(this).val().replace(/[^a-z A-Z 0-9]/g,'')
    }); 

That function also accepts 2 parameters and you should return your altered value. 该函数还接受2个参数,您应该返回更改后的值。

this comes from the doc: 这来自文档:

$('input').on('blur', function() {
  $(this).val(function( i, val ) {
    return val.toUpperCase();
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM