【发布时间】:2011-03-23 09:18:12
【问题描述】:
敬礼。我的 javascript 有一些问题..
我制作了翻译脚本,允许格鲁吉亚语用户通过拉丁字母输入格鲁吉亚语。 所以,当我在输入标签上进行操作时,我无法将焦点设置到文本的末尾。正确地,光标位于文本的末尾,但如果文本比输入标签大得多,它必须自动滚动且不得隐藏。
这里是代码..
$(document).ready(function() {
$(".geok").geokbd();
});
$.fn.geokbd = function() {
symbols = "abgdevzTiklmnopJrstufqRySCcZwWxjh";
this.relatedCheckbox = $("<input type=\"checkbox\" name=\"geokbd\" />").attr('checked', true);
$(this).after(this.relatedCheckbox);
$(this).keypress(
function(e) {
if ((e.charCode) == 96) {
if ($(this).next('input').attr('checked')) {
$(this).next('input').attr('checked', false);
} else {
$(this).next('input').attr('checked', true);
}
return false;
}
if ($(this).next('input').attr('checked')) {
if ((index = symbols.indexOf(String.fromCharCode(e.charCode))) >= 0) {
ret = String.fromCharCode(index + 4304);
this.focus();
var scrollTop = this.scrollTop,
start = this.selectionStart,
end = this.selectionEnd;
var value = this.value.substring(0, start) + ret + this.value.substring(end,this.value.length);
this.value = value;
this.scrollTop = scrollTop;
this.selectionStart = this.selectionEnd = start + ret.length;
return false;
}
}
}
);
}
谢谢
【问题讨论】:
-
据我了解,原因是我手动为输入元素插入值,并且在按键时返回 false。如果我返回真,一切正常,但不必要的符号。
标签: javascript jquery html string input