计算输入的符号的Textarea

时间:2017-11-28 12:41:41

标签: javascript tripadvisor

function someFunc(){
	var integer = document.getElementById('email').value.toString().length;
    var symbolCount = 0 + integer;
    // var last2 = 100 - integer2;

    if (symbolCount >= 100) {
        document.querySelector('.hidden_block').style.color = 'green';
    } 
    else if (symbolCount <= 100) {
    	 document.querySelector('.hidden_block').style.color = 'black';
    	 document.querySelector('.error').style.display = "block";
    } 
    else {
        document.getElementById('max').style.color = 'black';
    } 
   	
    document.getElementById('symbol_count').innerHTML = symbolCount;
}
email.addEventListener("click", function(){	
	document.querySelector('.hidden_block').style.display = 'block';
	document.getElementById('max').style.display = 'none';
});	
#max, #max2 {
	text-align: right;
	margin-right: 55px;
}
.hidden_block {
	display: none;
	text-align: right;
	margin-right: 55px;
}
.error {
	display: none;
	color: red;

}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<label for="email">Positive</label>
<textarea type="email" class="form-control" id="email" oninput="someFunc()"  placeholder="Tell people about your experience: describe the place or activity, recommendations for travelers?"></textarea>
<p id="max">Minimal length - symbols</p>
<div class="hidden_block">
  <span id="count">Symbols : <span id="symbol_count">0 </span> (minimum:100)</span>
</div>
 <span class="error">Your review must be at least 100 characters long. Adding details really helps travelers.</span>

大家好。我有一个简单的textarea字段。我需要实现像that这样的东西。当你写少于100个单词并点击电子邮件ID的外部时,边框颜色必须是红色。并且错误class必须显示。如果textarea字段为空,我需要如果用户将写任何符号id max max必须显示无符号,那么id max的标签p必须是显示块。谢谢你帮忙

0 个答案:

没有答案