But*_*her 37 javascript jquery keycode uppercase
当用户使用javascript键入时,我想将小写字母转换为大写.欢迎任何建议.
我尝试过以下方法:
$("#textbox").live('keypress', function (e) {
if (e.which >= 97 && e.which <= 122) {
var newKey = e.which - 32;
// I have tried setting those
e.keyCode = newKey;
e.charCode = newKey;
}
});
Run Code Online (Sandbox Code Playgroud)
ken*_*bec 56
css
#textbox{text-transform:uppercase}
Run Code Online (Sandbox Code Playgroud)
Sha*_*haz 23
$("#textbox").bind('keyup', function (e) {
if (e.which >= 97 && e.which <= 122) {
var newKey = e.which - 32;
// I have tried setting those
e.keyCode = newKey;
e.charCode = newKey;
}
$("#textbox").val(($("#textbox").val()).toUpperCase());
});
Run Code Online (Sandbox Code Playgroud)
这可能是一个很好的解决方法.只需在CSS中设置:
input#textbox {
text-transform: uppercase;
}
Run Code Online (Sandbox Code Playgroud)
如果您将数据发布到服务器端脚本(假设是php),您可以始终执行以下操作:
$upper_data = strtoupper($_POST['textbox']);
Run Code Online (Sandbox Code Playgroud)
嗨此代码适用于输入和textarea没有延迟或大写更改
$("#input").on('input', function(evt) {
var input = $(this);
var start = input[0].selectionStart;
$(this).val(function (_, val) {
return val.toUpperCase();
});
input[0].selectionStart = input[0].selectionEnd = start;
});
Run Code Online (Sandbox Code Playgroud)
混合来自/sf/answers/556087591/和/sf/answers/920890841/
| 归档时间: |
|
| 查看次数: |
93274 次 |
| 最近记录: |