0

嗨,我正在使用 SMS 面板,我想检查文本区域的长度,现在我正在使用这些代码:

        $("#txt").keydown(function () {
            var len = $(this).val().length;
            $("#lbl").text(len);
            if (len <= 70) {
                $("#lbl").text("One SMS");
                if (confirm("more than one sms are you sure?")) {
                    $("#lbl").text(len);
                }
            }
            else if (len >= 71 && len <= 133) {
                $("#lbl").text("two SMS");
                if (confirm("more than two sms are you sure?")) {
                    $("#lbl").text(len);
                }
            }
            else if (len > 134 && len <= 199) {
                $("#lbl").text("three SMS");
                alert("more than three sms are you sure?");
            }
        });

我想当我将文本粘贴到 textArea 时显示警报并选择 no cant input any

谢谢你的建议?

4

2 回答 2

2

你的意思是:

else if (len >= 71 && len <= 133) {
     $("#lbl").text("two SMS");
     if (confirm("more than two sms are you sure?")) {
         $("#lbl").text(len);
     }
}
else if (len >= 134 && len <= 199) {
       $("#lbl").text("three SMS");
       alert("more than three sms are you sure?");
}
于 2012-10-29T06:27:23.767 回答
0

但它并不完美,

我可以看到的一个错误是,它不能完美地工作,你已经使用 keydown 事件来查找长度,所以如果你复制和粘贴没有发生 Keydown 事件,所以你找不到那里的长度,所以您可以在文本框的 onchange 事件中编写相同的函数,以便在复制和粘贴数据时也可以找到长度

  $("input").change(function(){
    //your function of finding the length goes here
  });

如果您发布确切的问题,将更容易获得帮助。

希望这会有所帮助:D

于 2012-10-29T07:00:21.810 回答