jQuery 帮助 $(this).val() toUpperCase()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2813166/
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
help with $(this).val() toUpperCase()
提问by Rod
Given:
鉴于:
<script type="text/javascript">
$(document).ready(function () {
var str = 'Test';
//alert(str.toUpperCase());
$('#stringFinder').keyup(function (e) {
alert($(this).val()==str.toUpperCase());
});
});
</script>
How do I make $(this).val() all upper case to get a like comparison using contains?
如何使 $(this).val() 全部大写以使用 contains 进行类似比较?
Thanks, rodchar
谢谢,罗德查尔
回答by karim79
$(this).val()
returns a String object, which means you perform any String methodson it, so:
$(this).val()
返回一个String 对象,这意味着您可以对其执行任何String 方法,因此:
alert($(this).val().toUpperCase() === str.toUpperCase());
alert($(this).val().toUpperCase() === str.toUpperCase());
回答by xandercoded
$('#stringFinder').keyup(function (e) {
alert($(this).val().toUpperCase() == str.toUpperCase());
});
回答by fabian
Try this:
尝试这个:
$(".solomayus").keypress(function (event) {
$(this).val($(this).val().toUpperCase());
});
OR
或者
$('.solomayus').blur(function () {
$(this).val($(this).val().toUpperCase());
});