Ram*_*amy 10 javascript css jquery
我在输入时使用以下代码转换为大写.
$(".input_capital").live('keypress', function(e)
{
var defaultStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var checkstr = $(this).val();
var str1 = '';
for (i = 0; i < checkstr.length; i++)
{
var ch = checkstr.charCodeAt(i);
if (ch>=97 && ch<=122){
str1 += defaultStr.charAt(ch-97);
}else{
str1 += checkstr.charAt(i);
}
}
$(this).focus();
$(this).val(str1);
});
Run Code Online (Sandbox Code Playgroud)
以下代码
$(".input_capital").live('keypress', function(e)
{
$(this).val($(this).val().toUpperCase());
});
Run Code Online (Sandbox Code Playgroud)
以上所有代码都运行正常.但对于能够查看较低情况一段时间的用户.之后只有它转换为大写.
我text-transform: uppercase在css中试过' '.但它不适用于Android Os的三星标签.请任何人帮助我通过脚本实现这一目标.
Yos*_*shi 22
你可以试试:
$(".input_capital").on('keydown', function(evt) {
$(this).val(function (_, val) {
return val + String.fromCharCode(evt.which).toUpperCase();
});
return false;
});?
Run Code Online (Sandbox Code Playgroud)
它有一些缺陷,但我认为这个想法是明确的,并且可以建立在其上.
更好的版本,但要注意inputIE <9中不支持的事件.
$('.input_capital').on('input', function(evt) {
$(this).val(function(_, val) {
return val.toUpperCase();
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class='input_capital' rows='8'></textarea>Run Code Online (Sandbox Code Playgroud)
Som*_*Guy 21
Note: This answer is without delay..if you like to avoid Jquery
尝试
<input type="text" style="text-transform: uppercase">
Run Code Online (Sandbox Code Playgroud)
如果您不在乎 ie<9 ,请听“输入”事件
$(".input_capital").bind("input", function(e){
this.value = this.value.toUpperCase();
});
Run Code Online (Sandbox Code Playgroud)
对于 IE<9,请改用“keyup”
演示:http : //jsfiddle.net/MupXZ/6/