在javascript中将小写字母转换为大写 [英] Convert lowercase letter to upper case in javascript
本文介绍了在javascript中将小写字母转换为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个代码将小写字母转换为大写字母,但它仅适用于IE而不适用于Crome或Firefox。
I have a code that will convert lower case letters to uppercase but it works only with IE and not in Crome or Firefox.
function ChangeToUpper()
{
key = window.event.which || window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}
<asp:TextBox ID="txtJobId" runat="server" MaxLength="10" onKeypress="ChangeToUpper();"></asp:TextBox>
即使我尝试了
document.getElementById("txtJobId").value=document.getElementById("txtJobId").value.toUpperCase();
onBlur文本框事件
我该怎么做才能使它在所有浏览器中都有效?
What should I do to make it work in all browsers?
谢谢
推荐答案
<script type="text/javascript">
function ChangeCase(elem)
{
elem.value = elem.value.toUpperCase();
}
</script>
<input onblur="ChangeCase(this);" type="text" id="txt1" />
从您的HTML中分离javascript
separate javascript from your HTML
window.onload = function(){
var textBx = document.getElementById ( "txt1" );
textBx.onblur = function() {
this.value = this.value.toUpperCase();
};
};
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
如果文本框位于命名容器内,则使用类似这样的内容
If the textbox is inside a naming container then use something like this
var textBx = document.getElementById ("<%= txt1.ClientID %>");
textBx.onblur = function() {
this.value = this.value.toUpperCase();
};)
这篇关于在javascript中将小写字母转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文