jQuery 如何控制或将所有文本更改为大写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9587542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to control or change all the text to upper case
提问by Alejandro Hinestrosa
I'm developing a few forms for my company to use. I consult and insert data into the database, but for standard issues I want to transform the text I enter to uppercase, How I do that?
我正在开发一些表格供我的公司使用。我咨询并将数据插入数据库,但对于标准问题,我想将输入的文本转换为大写,我该怎么做?
Example of one of my forms:
我的一种表格示例:
I want the text fields I enter in automatically transformed to uppercase, or the data that I enter into my database already transformed to uppercase (in the case that the user doesn't enter it that way).
我希望我输入的文本字段自动转换为大写,或者我输入到数据库中的数据已经转换为大写(如果用户没有以这种方式输入)。
EDIT:
编辑:
I try
我试试
$("tbCiudad").change(function() {
$(this).val($(this).val().toUpperCase());
});
or
或者
$("tbCiudad").keyup(function() {
$(this).val($(this).val().toUpperCase());
});
and nothing happens to that field. What am I doing wrong?
该领域没有任何反应。我究竟做错了什么?
回答by Marius Ilie
$("input[type=text]").keyup(function(){
$(this).val( $(this).val().toUpperCase() );
});
回答by MilkyWayJoe
You can add an event handler with javascript (or jquery if you want) to keypress
or blur
events of those textboxes and then apply what Jay Blanchard suggested. Something like this:
您可以将带有 javascript(或 jquery,如果需要)的事件处理程序添加到这些文本框的keypress
或blur
事件,然后应用 Jay Blanchard 建议的内容。像这样的东西:
$("input[type='text']").bind("blur", null, function(e) {
$(this).val($(this).val().toUpperCase());
});
回答by Jay Blanchard
Using plain old JavaScript use toUpperCase()
使用普通的旧 JavaScript 使用 toUpperCase()
回答by goenning
Do you want to save it or only show it in UPPERCASE?
你想保存它还是只以大写显示?
If you need only to show, you can you CSS:
如果你只需要显示,你可以使用 CSS:
<style type="text/css">
input {
text-transform:uppercase;
}
</style>
If you want to save it in uppercase, the server-side is the best way to do it. I suggest creating a custom ModelBinder that would call String.ToUpperon every string property.
如果你想以大写形式保存它,服务器端是最好的方法。我建议创建一个自定义的 ModelBinder,它会在每个字符串属性上调用String.ToUpper。
You can also mix both of this strategies.
您也可以混合使用这两种策略。
回答by Vineesh Kalarickal
Use this Function
使用此功能
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$("#text_field_id").keyup(function() {
$(this).val($(this).val().toUpperCase());
});
});
</script>
回答by Kamran Ali
You can use the javacsript method toUpperCase()
for this conversion.
您可以使用 javacsript 方法toUpperCase()
进行此转换。
回答by kayfun
Use javascript toUpperCase method.
使用 javascript toUpperCase 方法。
I am also sure there is a function in ASP to do that such as strtoupper in PHP
我也确定 ASP 中有一个函数可以做到这一点,例如 PHP 中的 strtoupper
回答by Siva Charan
Just apply CSS class to all required fields:-
只需将 CSS 类应用于所有必填字段:-
.uppercase
{
text-transform: uppercase;
}