在javascript中将小写字母转换为大写字母
我有一个将小写字母转换为大写字母的程序,但它只适用于IE,而不适用于Crome或Firefox在javascript中将小写字母转换为大写字母,javascript,Javascript,我有一个将小写字母转换为大写字母的程序,但它只适用于IE,而不适用于Crome或Firefox function ChangeToUpper() { key = window.event.which || window.event.keyCode; if ((key > 0x60) && (key < 0x7B)) window.event.keyCode = key-0x
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>
文本框的onBlur事件
我应该怎么做才能使它在所有浏览器中都工作
谢谢您是否尝试过
.toUpperCase()
链接:
文本转换:大写
,然后在提交时运行。或者您只是混合提交,在服务器端用大写字母:)
功能变更案例(elem)
{
elem.value=elem.value.toUpperCase();
}
将javascript与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>
window.onload=function(){
var textBx=document.getElementById(“txt1”);
textBx.onblur=函数(){
this.value=this.value.toUpperCase();
};
};
如果文本框位于命名容器中,则使用如下内容
var textBx = document.getElementById ("<%= txt1.ClientID %>");
textBx.onblur = function() {
this.value = this.value.toUpperCase();
};)
var textBx=document.getElementById(“”);
textBx.onblur=函数(){
this.value=this.value.toUpperCase();
};)
如果您不想创建一个显式JavaScript函数,在这里您只需一行即可完成:
分别转换为小写和大写:
<asp:TextBox ID="txt1" onblur='this.value = this.value.toLowerCase();'></asp:TextBox>
<asp:TextBox ID="txt1" onblur='this.value = this.value.toUpperCase();'></asp:TextBox>
我认为最简单的方法是
<input id="yourid" style="**text-transform: uppercase**" type="text" />
您试过这个吗
var myString = "this is a String";
alert(myString.toUpperCase()); // "THIS IS A STRING"
alert(myString.toLowerCase()); // "this is a string"
谢谢。。。希望你喜欢。太难了,伙计!从头开始编写函数更简单的方法是:D@Priyanka-您在函数上收到的错误是什么?基本函数不工作是没有意义的@lol:P
<input id="yourid" style="**text-transform: uppercase**" type="text" />
var myString = "this is a String";
alert(myString.toUpperCase()); // "THIS IS A STRING"
alert(myString.toLowerCase()); // "this is a string"