我有3个电话号码文本框。当用户键入时,它会自动从一个文本框移动到另一个文本框。当用户按退格键时,我可以将焦点移至上一个文本框。问题是,在IE中,焦点设置在文本框的开头。这是我的代码,可以在Chrome中正常工作。设置文本框中最后一个字符后的焦点
$('#AreaCode').live('keyup', function (event) {
if ($(this).val().length == $(this).attr("maxlength"))
$('#Prefix').focus();
});
$('#Prefix').live('keyup', function (event) {
if (event.keyCode == 8 && $(this).val().length == 0)
$('#AreaCode').focus();
if ($(this).val().length == $(this).attr("maxlength"))
$('#Number').focus();
});
$('#Number').live('keyup', function (event) {
if (event.keyCode == 8 && $(this).val().length == 0)
$('#Prefix').focus();
});
如何在倒退时在内容末尾设置焦点?
的重复http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element – 2011-01-05 21:40:12
另一个简单的方法在这里:http://stackoverflow.com/a/19568146/1032372 – shim 2014-11-25 21:29:37