2012-02-22 82 views

回答

5

你可以使用keyup()toUpperCase()

$('input').keyup(function(){ 
    this.value = this.value.toUpperCase(); 
}); 

小提琴這裏http://jsfiddle.net/GT7fY/2/

3

我只想把它轉換在提交事件爲大寫。

$("#verify input").val(function(i,val){ 
    return val.toUpperCase(); 
}); 

大寫的要求可以簡單地保持對用戶隱藏。

+0

我同意。如果用戶看到它是大寫字母並不重要,就不要打擾並繼續。相反,甚至可以在後端進行轉換。 – 2012-02-22 17:03:05

2
$('form#verify').on('keyup', 'input', function(event) { 
    $(this).val($(this).val().toUpperCase()); 
}); 

2

底部粘貼此:

$(document).ready(function(e){ 
    $('input[type="text"]').on('keyup', function(){ 
    $(this).val(this.value.toUpperCase()); 
    }); 
}); 
2
$(":input").keyup(function() { 
$(this).val($(this).val().toUpperCase()); 
}); 

都是你的。

4

試試這個:

style input 
input{text-transform:uppercase;}​ 

and onBlur make uppercase 
<input onBlur="$(this).val(this.value.toUpperCase());"> 

就是這樣:)

+1

+1這是最好的方法:) – 2012-02-22 17:00:53

+0

但是沒有問到什麼,它必須是像onkeyup =「this.value = this.value.toUpperCase();」在純JS使它最有效率.... – 2012-02-22 17:06:24

+0

@Likwid_T任何你應該設計它的樣式。 – 2012-02-22 17:17:42

相關問題