我希望使用JavaScript强制文本框的值为小写。我试过下面的代码,但每次你按一个键,光标都会跳到输入的末尾。我怎样才能避免这种情况?
$("#beLowerCase").keyup(function(){
$(this).val( $(this).val().toLowerCase() );
});
发布于 2013-01-25 03:06:34
$("#beLowerCase").on('input', function(){
// store current positions in variables
var start = this.selectionStart,
end = this.selectionEnd;
this.value = this.value.toLowerCase();
// restore from variables...
this.setSelectionRange(start, end);
});
(fiddle)
这实际上也适用于CSS:
#beLowerCase{
text-transform:lowercase;
}
服务器可以处理实际的下层...
https://stackoverflow.com/questions/14508707
复制相似问题