【发布时间】:2020-07-08 17:15:10
【问题描述】:
我在尝试验证绕过 textarea 字段中的 maxlength 值的用户时遇到了问题,但我的验证似乎都不起作用。我正在尝试验证用户是否可以将 maxlength 更改为超出我们的初始限制,或者是否从元素中删除了 maxlength。
这很容易做到,但有些用户似乎正在这样做。
这是我的代码:
<form class="forms" action="/checkout" name="ordersubmit" id="shipping" method="post" novalidate="">
<div class="col-xs-12 col-sm-offset-1 col-sm-11 noPadding">
<label class="InstructionsBlock" for="Instructions">
Instructions
</label>
<textarea id="Instructions" name="Instructions" maxlength="62" rows="6" cols="50">
</textarea>
</div>
</form>
var instructions = $("#Instructions");
$("form").submit() {
if (instructions.val(instructions.attr("maxlength")) > 70 || instructions.length) {
alert("Please limit your instruction to a maximum of 70 characters");
}
}
提交表单时,它不会验证,解决方案可能比我想象的要容易,但我似乎无法完成这项工作。
【问题讨论】:
-
我不清楚你想用这个检查什么:if (instructions.val($(this).attr("maxlength")) > 70 || instructions.length)跨度>
-
我也用 html 编辑了我的代码
-
我已编辑我的答案以更适用于您的代码