我正在使用 Tawk 在我的网站上聊天。我想将文本数量限制为 11 位数字。
<input type="text" id="prechat2Field" title="Phone" value="" class="textInput" maxlength="20" placeholder=" Phone">
我无法更改他们的核心文件。可以使用 Jquery 完成吗?
最佳答案
您可以覆盖该元素的属性 maxlength
:
$('#prechat2Field').prop('maxlength',11);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<input type="text" id="prechat2Field" title="Phone" value="" class="textInput" maxlength="20" placeholder=" Phone">
关于javascript - 使用 Jquery 限制输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34656062/