jQuery 的小写和大写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5619102/
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
Lowercase and Uppercase with jQuery
提问by Kris-I
How do I transpose a string to lowercase using jQuery? I've tried
如何使用 jQuery 将字符串转为小写?我试过了
var jIsHasKids = $('#chkIsHasKids').attr('checked').toLowerCase();
but it doesn't work. What am I doing wrong?
但它不起作用。我究竟做错了什么?
回答by karim79
I think you want to lowercase the checked value? Try:
我想你想小写选中的值?尝试:
var jIsHasKids = $('#chkIsHasKids:checked').val().toLowerCase();
or you want to check it, then get its value as lowercase:
或者您想检查它,然后将其值设为小写:
var jIsHasKids = $('#chkIsHasKids').attr("checked", true).val().toLowerCase();
回答by Spudley
If it's just for display purposes, you can render the text as upper or lower case in pure CSS, without any Javascript using the text-transform
property:
如果只是为了显示目的,您可以在纯 CSS 中将文本呈现为大写或小写,而无需使用该text-transform
属性的任何 Javascript :
.myclass {
text-transform: lowercase;
}
See https://developer.mozilla.org/en/CSS/text-transformfor more info.
有关更多信息,请参阅https://developer.mozilla.org/en/CSS/text-transform。
However, note that this doesn't actually change the value to lower case; it just displays it that way. This means that if you examine the contents of the element (ie using Javascript), it will still be in its original format.
但是,请注意,这实际上并没有将值更改为小写;它只是以这种方式显示它。这意味着如果您检查元素的内容(即使用 Javascript),它仍将是其原始格式。
回答by r.piesnikowski
Try this:
尝试这个:
var jIsHasKids = $('#chkIsHasKids').attr('checked');
jIsHasKids = jIsHasKids.toString().toLowerCase();
//OR
jIsHasKids = jIsHasKids.val().toLowerCase();
Possible duplicate with: How do I use jQuery to ignore case when selecting
可能重复: 如何在选择时使用 jQuery 忽略大小写