按箭头键时光标跳跃 [英] cursor is jumping when pressing the arrow keys

查看:72
本文介绍了按箭头键时光标跳跃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,其中禁止输入禁止的字符。 #。

I have a textbox, where a forbidden character cant be typed. #.

但是,当文本框填入数据时,我将焦点放在文本框的中间,然后我使用箭头键向左和向右,然后它跳到文本框的末尾。

This works, however, when the textbox is filled in with data, and I put the focus on the middle of the textbox and then I use the arrow keys to go left and right, then it jumps to the end of the textbox.

如果我也在文本框的中间键入一个字符,它会再次结束

If I type a character also in the middle of the textbox, it goes to the end again

$('[id$=txtClient]').keyup(function () {
        EnableClientValidateButton(); // When the textbox changes, the user has the ability to validate the client
        ChangeColorClient("0"); // The color is changed to white, to notify the user the client is not validated yet.
        var $el = $('[id$=txtClient]'); // the text element to seach for forbidden characters.
        var text = $el.val(); // The value of the textbox
        text = text.split("#").join("");//remove occurances of forbidden characters, in this case #
        $el.val(text);//set it back on the element
    });


推荐答案

这有点不愉快,我不是100%满意,但它解决了你所有的问题......

This is a bit unpleasant, and I'm not 100% happy, but it solves all the given issues that you've had...

$("[id$=txtClient]").keyup(function (e) {
    var text = $(this).val();
    if (text.indexOf("#") > -1) {
        text = text.replace("#", "");
        $(this).val(text);
    }
});

这是一个jsFiddle示例......

Here's a jsFiddle example...

http://jsfiddle.net/E4cBK/

这篇关于按箭头键时光标跳跃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆