js杂记

 1   很久以前

<html><

head>

 function setLength()
    {
      if (document.getElementById("radA").checked==true)
      {document.form1.txtA.attributes['maxLength'].value=8;}
      if (document.getElementById("radB").checked==true)
       {document.form1.txtA.attributes['maxLength'].value=12;}
    }
    </script>

</head>

<body>

<form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>

<asp:RadioButton GroupName="a" ID="radA"  runat=server  Text="A"/><asp:RadioButton GroupName="a" ID ="radB" Text="B" runat=server /><br>
    <asp:TextBox ID ="txtA" runat=server onfocus="setLength()"></asp:TextBox>

</td>
    </tr>
    </table>
    </div>
    </form>

</body>

</html>

2、使用js使输入文本自动转换大小写:

 function ConvertStr(control, IsToUpper) {
        var cValue = control.value;
        if (IsToUpper == "1") {
            control.value = cValue.toUpperCase();
        }
        else {
            control.value = cValue.toLowerCase();
        }
    }

<txt:CustomTextBox ID="txtPrinterSN" runat="server" IsNull="false" TextType="Text" onkeyup="ConvertStr(this,1);"></txt:CustomTextBox>

 

3、使用js控制输入字符串长度

 

 function checkLength(obj, maxlength, isChs) {
     var conValue = obj.value;
     if (conValue.length > maxlength) {
         conValue = conValue.substring(0, maxlength);
         obj.value = conValue;
     }
     if (isChs == "0") {
         if (conValue.length > 0) {
             if (/[^\x00-\xff]/g.test(conValue)) {
                 conValue = conValue.replace(/[\u4e00-\u9fa5]/g, '');
                 if (conValue.length > 0) {
                     obj.value = conValue;
                 }
                 else {
                     obj.value = "";
                 }
             }
         }
     }
 }
<asp:TextBox ID="txtFaultDescription_NotNull" runat="server" Width="500px" MaxLength="250"  TextMode="MultiLine" onpropertychange="checkLength(this,290,0)"></asp:TextBox>



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jerryzhao58

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值