[英]Autofill/Autocomplete not working, if the form has more than 200 input fields
[英]How to prompt a message in textarea if input is more than 200 characters
如果输入超过200个字符,如何在文本区域中提示错误消息。 我正在尝试maxLength属性。 但是它停止接受输入。 我不想要那个。 我想要一个错误消息
尝试编写一个使用onchange属性在输入更改上调用的Jquery函数。 然后使用var messageTxt = $("#yourelementid").value(); If(messageTxt.length() > 200) { alert("input is more than 200 characters"); }
var messageTxt = $("#yourelementid").value(); If(messageTxt.length() > 200) { alert("input is more than 200 characters"); }
<style type="text/css">
.input-error ::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: red;
}
.input-error :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: red;
opacity: 1;
}
.input-error ::-moz-placeholder { /* Mozilla Firefox 19+ */
color: red;
opacity: 1;
}
.input-error :-ms-input-placeholder { /* Internet Explorer 10-11 */
color: red;
}
</style>
<div class="text-wrapper">
<textarea id="infoText" placeholder="Type your text"></textarea>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#infoText').bind('input propertychange', function() {
if($(this).val().length>4){
$(this).parent(".text-wrapper").addClass("input-error");
$(this).attr("placeholder","Text cannot exceed more than 200 characters")
$(this).val("");
}
else{
$(this).parent(".text-wrapper").removeClass("input-error")
} ;
});
});
</script>
由于您的帖子带有角度标签,因此我假设您使用的是角度标签。 通常,您可以在textarea模型上放置手表。
$scope.$watch('yourTextAreaModel', function(newVal) {
if(newVal.length > 200){
alert("input cannot be more than 200 characters");
}
})
*您甚至可能不需要手表,但这取决于您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.