开发者

jQuery change keypress to text field

I am looking for a cross-browser (can be based on jquery) way to change the keypress done by a user.

Capturing it is no problem. Changing behaviour in a cross-browser compatible manner, seems to be a problem.

Essentially I need to map some extra keys to special characters. Like ctrl+alt+p should enter a special character in a 开发者_如何学Gotext field or textarea.

Thanks,

-dennis


You can capture a key press, look at the event to see if CTRL or ALT has been pressed. I assume this is pretty much what you are doing?

$(document).ready(function() 
{
    $("#target").keydown(function(event) 
    {
        if (event.ctrlKey && event.altKey && event.keyCode == '80') {
            alert("Ctrl-Alt-P combination");
        }
    }
});


I've covered a cross-browser technique for doing this before on SO: Can I conditionally change the character entered into an input on keypress?

You can adapt this for your own mappings. Also, you should use the keydown rather than keypress event if you're detecting keystrokes involving Ctrl or Alt, since not all browser will fire keypress events when no character is typed.


Inserting a text where cursor is using Javascript/jquery

http://skfox.com/jqExamples/insertAtCaret.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜