jquery用户输入大写不适用于某些情况

时间:2017-12-20 13:26:56

标签: javascript jquery browser uppercase

我使用Jquery实时覆盖用户对大写的输入。但是我收到的一些数据大概不是2%左右。我可以知道可能导致这种情况吗?

//convert all lower case to upper case
$("input, textarea").not("[data-controlname='txtCompanyEmailAddress'] input," +
                    "[data-controlname='KeyAccEmailaddress'] input," +
                    "[data-controlname='AccDeptEmailaddress'] input," +
                    "[data-controlname='CompanyEmail'] input," +
                    "[data-controlname='CompanyURL'] input," +
                    "[data-controlname='txtInternalComment'] textarea," +
                    "[data-controlname='txtRejectCommentToSupplier'] textarea"
                    ).on('input', function(evt) {
          var input = $(this);
          var start = input[0].selectionStart;
          $(this).val(function (_, val) {


            return val.toUpperCase();
          });
          input[0].selectionStart = input[0].selectionEnd = start;
 });

1 个答案:

答案 0 :(得分:0)

如果没有具体原因你使用javascript,另一种方法是将以下内容添加到你的CSS中:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>AppIDName</key>
    <string>[appPublicName]</string>
    <key>ApplicationIdentifierPrefix</key>
    <array>
    <string>[teamId]</string>
    </array>
    <key>CreationDate</key>
    <date>2017-07-06T11:55:52Z</date>
    <key>Platform</key>
    <array>
        <string>iOS</string>
    </array>
    <key>DeveloperCertificates</key>
    <array>
        <data>[devCert]</data>
    </array>
    <key>Entitlements</key>
    <dict>
        <key>keychain-access-groups</key>
        <array>
            <string>[teamId].*</string>     
        </array>
        <key>get-task-allow</key>
        <false/>
        <key>application-identifier</key>
        <string>[teamId].[appname]</string>
        <key>com.apple.developer.associated-domains</key>
        <string>*</string>
        <key>com.apple.developer.team-identifier</key>
        <string>[teamId]</string>
        <key>aps-environment</key>
        <string>production</string>
    </dict>
    <key>ExpirationDate</key>
    <date>2018-04-25T13:18:41Z</date>
    <key>Name</key>
    <string>[appPublicName]</string>
    <key>ProvisionedDevices</key>
    <array>
        [provisioned devices]
        [The device I'm trying to deploy to is listed here]
    </array>
    <key>TeamIdentifier</key>
    <array>
        <string>[teamId]</string>
    </array>
    <key>TeamName</key>
    <string>[teamName]</string>
    <key>TimeToLive</key>
    <integer>293</integer>
    <key>UUID</key>
    <string>[id]</string>
    <key>Version</key>
    <integer>1</integer>
</dict>
</plist>

然后将.uppercase { text-transform: uppercase; } 类添加到每个始终需要以大写形式显示其值的输入元素。