Gus*_*yes 21 html javascript jquery
我希望在提交表单之前将所有表单值更改为大写.
到目前为止,我有这个,但它不起作用.
$('#id-submit').click(function () {
var allInputs = $(":input");
$(allInputs).value.toUpperCase();
alert(allInputs);
});
Run Code Online (Sandbox Code Playgroud)
Sel*_*gam 44
试试如下,
$('input[type=text]').val (function () {
return this.value.toUpperCase();
})
Run Code Online (Sandbox Code Playgroud)
您应该使用input[type=text]而不是:input或input我认为您的意图仅在文本框上操作.
Amr*_*dra 16
使用css:
input.upper { text-transform: uppercase; }
Run Code Online (Sandbox Code Playgroud)
可能最好使用该样式,并转换服务器端.还有一个强制大写的jQuery插件:http://plugins.jquery.com/plugin-tags/uppercase
$('#id-submit').click(function () {
$("input").val(function(i,val) {
return val.toUpperCase();
});
});
Run Code Online (Sandbox Code Playgroud)
小智 5
使用 css text-transform 显示所有输入类型文本中的文本。在 Jquery 中,您可以在模糊事件时将值转换为大写。
CSS:
input[type=text] {
text-transform: uppercase;
}
Run Code Online (Sandbox Code Playgroud)
jQuery:
$(document).on('blur', "input[type=text]", function () {
$(this).val(function (_, val) {
return val.toUpperCase();
});
});
Run Code Online (Sandbox Code Playgroud)