限制文本域多少字体

1.首先第一步,我们需要设置.textare的html
在这里插入图片描述

 <div class="layui-input-inline tcp_box">
                    <textarea name="apply_require" lay-filter="apply_require" id="apply_require"
                              class="layui-input applyRequest tcp_content" placeholder="请输入活动报名要求"  style="width: 340px;height: 80px;padding: 5px 8px;"
                              maxlength="500"
                              onchange="this.value=this.value.substring(0,500)"
                              onkeydown="this.value=this.value.substring(0,500)"
                              onkeyup="this.value=this.value.substring(0,500)"></textarea>
                    <p class="pl_tcp"></p>
                    <span class="t_h"><i>0</i>/500</span>
                </div>

2.js代码的设置

  //文本域的计算
        $(".tcp_content").focus(function () {
            if ($(this).val() == "") {
                $(".tcp_box p").css('display', 'none')
            }
        }).blur(function () {
            if ($(this).val() == "") {
                $(".tcp_box p").css('display', 'block')
            } else {
                $(".tcp_box p").css('display', 'none')
            }
        })

        $(".pl_tcp").click(function () {
            $(this).css('display', 'none');
            $(".tcp_content").focus();
        })

        $(".tcp_content").change(function () {
            $(".t_h i").html($(".tcp_content").val().length);
        })
        $(".tcp_content").keydown(function () {
            $(".t_h i").html($(".tcp_content").val().length);
        })
        $(".tcp_content").keyup(function () {
            $(".t_h i").html($(".tcp_content").val().length);
        })

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值