Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果我在样式中设置默认大写,如何在同一文本框中混合输入大写和小写字母?_Php_Html - Fatal编程技术网

Php 如果我在样式中设置默认大写,如何在同一文本框中混合输入大写和小写字母?

Php 如果我在样式中设置默认大写,如何在同一文本框中混合输入大写和小写字母?,php,html,Php,Html,我将默认文本设置为html样式中文本框的大写(,即style=“text transform:uppercase”) 我的问题是, 我需要在文本框中输入大写字母和小写字母的混合,如下所示 全球国际私人有限公司 我该怎么办?请任何人帮我一个忙。我假设您希望默认文本条目为大写,但在适当的时候允许小写(就像大写锁定键被锁定一样)。因此,我建议您不要指定所有封口的默认样式。您可以使用JavaScript截取正在键入的文本,并像锁定caps lock键一样操作文本: 这是我的完整(以及自测试以来)测试页面

我将默认文本设置为html样式中文本框的大写(,即style=“text transform:uppercase”

我的问题是, 我需要在文本框中输入大写字母和小写字母的混合,如下所示

全球国际私人有限公司


我该怎么办?请任何人帮我一个忙。

我假设您希望默认文本条目为大写,但在适当的时候允许小写(就像大写锁定键被锁定一样)。因此,我建议您不要指定所有封口的默认样式。您可以使用JavaScript截取正在键入的文本,并像锁定caps lock键一样操作文本:

这是我的完整(以及自测试以来)测试页面代码(根据我的原始答案编辑,根据我下面的评论):


测试页
//

注意:如果用户按下/锁定Caps Lock键,此代码将具有操作文本框中字符串的效果,就像该键未被锁定一样!(对任何感兴趣的人来说,txtchk()函数都可以被编辑来做各种有趣的事情;我通常用它来删除我不希望用户键入的字符。)

答案代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Change caps to small</title>
<script type="text/javascript">
var bx, chr, indx, intvl, last, lng, ln2, str, tmp;
function PrepBox()
{
    bx = document.getElementById("txtbx");
    last = "";     //this will be the manipulated string
    lng = 0;       //its length
    intvl = setInterval("txtchk();", 100); //ten times per second
    return;
}
function txtchk()
{ 
tmp = bx.value;
ln2 = tmp.length;

if(ln2 < lng) //test for backspace
    last = tmp.substr(0,ln2);  //shorten the manipulated string

else if(ln2 > lng)
{ 
    str = tmp.substr(lng);   //get newly-typed character(s)

    for(indx=0; indx<str.length; indx++)  //for each one of them
    { 
        chr = str.charAt(indx);  
        if((chr >= "a") && (chr <= "z"))
            last += chr.toUpperCase();   //change lowercase to upper
        else  if((chr >= "A") && (chr <= "Z"))
            last += chr.toLowerCase();   //change uppercase to lower
        else
            last += chr;   //periods, commas, semicolons, ...
    }
}
lng = ln2;  //update saved-length of "last"
bx.value = last; //replace text in box with manipulated string
return;
}
</script>
</head>
<body>
<input id="txtbx" size="50" maxlength="40" type="text" style="font-size:10pt;" onFocus="PrepBox();" />
</body>
</html>

把帽子换成小的
变量bx、chr、indx、intvl、last、lng、ln2、str、tmp;
函数PrepBox()
{
bx=document.getElementById(“txtbx”);
last=”“;//这将是被操纵的字符串
lng=0;//其长度
intvl=setInterval(“txtchk();”,100);//每秒十次
返回;
}
函数txtchk()
{ 
tmp=bx.值;
ln2=tmp.长度;
if(ln2液化天然气)
{ 
str=tmp.substr(lng);//获取新键入的字符

对于(indx=0;indx=“a”)&&&&(chr=“a”)&&&(chr So..您需要遵循什么规则?默认文本框值应为大写(我将文本转换设置为大写)。如果我想在文本之间输入小写字母(例如GLOBAL International PVT Ltd),我将使用shift键更改小箱子。是否可以这样做?谢谢您的快速回复。我的要求是示例1 HAPAG LLOYD INDIA PRIVATE LIMITED示例2 MAERSK INDIA Pvt ltd通常我只键入示例1。在极少数情况下,我需要输入类似示例2的规定是否有这样做的可能性?请注意,我根本不想使用大写锁定。如果未按下大写锁定键,我提供的代码应该完全符合您的要求。如果文本框中键入的所有内容以小写开头,并且如果它以大写开头(如按住shift键时),则会将其转换为大写,这些字符仅转换为小写。请注意,JavaScript代码仅影响文本框中的文本,而不影响在其他地方键入的文本(小写和大写通常会传递到其他地方)。我使用了您的代码,但它仅转换为小写(即使我尝试输入大写).基本上,默认情况下,我只在文本框内键入大写字符。如果我需要大写字母之间的小写字母,请按shift键键入小写字母。可以这样做吗???我承认我在发布代码之前没有测试过代码,但实际上它基本上是有效的——这一行从((chr>=“A”)开始如果((chr>=“A”)(我将编辑上面的代码来修复它;如果您在测试中捕获并修复了它,很好!),那么实际上应该开始其他操作。我能想到的唯一一件可能导致问题的事情是,如果您仍然使用style=“text transform:uppercase”(或类似的东西)与文本框关联。取出它!@vernoner3voltazim这不是你写的东西吗?这是我完整(并经过测试)的测试页面代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Change caps to small</title>
<script type="text/javascript">
var bx, chr, indx, intvl, last, lng, ln2, str, tmp;
function PrepBox()
{
    bx = document.getElementById("txtbx");
    last = "";     //this will be the manipulated string
    lng = 0;       //its length
    intvl = setInterval("txtchk();", 100); //ten times per second
    return;
}
function txtchk()
{ 
tmp = bx.value;
ln2 = tmp.length;

if(ln2 < lng) //test for backspace
    last = tmp.substr(0,ln2);  //shorten the manipulated string

else if(ln2 > lng)
{ 
    str = tmp.substr(lng);   //get newly-typed character(s)

    for(indx=0; indx<str.length; indx++)  //for each one of them
    { 
        chr = str.charAt(indx);  
        if((chr >= "a") && (chr <= "z"))
            last += chr.toUpperCase();   //change lowercase to upper
        else  if((chr >= "A") && (chr <= "Z"))
            last += chr.toLowerCase();   //change uppercase to lower
        else
            last += chr;   //periods, commas, semicolons, ...
    }
}
lng = ln2;  //update saved-length of "last"
bx.value = last; //replace text in box with manipulated string
return;
}
</script>
</head>
<body>
<input id="txtbx" size="50" maxlength="40" type="text" style="font-size:10pt;" onFocus="PrepBox();" />
</body>
</html>