我创建了一个带有列表框和文本区域的简单页面,其中包含所有条件都需要的条件。
列表框工作正常,但textarea框不会告诉该字段是否需要填充。
<!DOCTYPE html>
<html>
<head>
<title>Ratings & Reviews</title>
<body>
<form>
<span>Customer Service*</span>
<span>
<select name=customer id=aa required>
<option selected="rate" value="" disabled>rate</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select>
</span>
<br><br>
<span>Value for money*</span>
<span>
<select name=money id=aa required>
<option selected="rate" value="" disabled>rate</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select>
</span>
<div>
<textarea name="reviews" rows=11 cols=50 maxlength=250 required>
</textarea>
</div>
<div id=submit>
<br>
<input type=submit name=submit value=submit>
</div>
</form>
</body>
</html>
文本区域内有空格,将其删除:
<textarea name="reviews" rows=11 cols=50 maxlength=250 required ></textarea>
问题在于标签之间的空格。您不应该在这些标记之间的html中给出任何空格,否则浏览器会将其视为值。
试试这个
<textarea name="mm" id="mm" rows="5" placeholder="NA if not applicable" required="required"></textarea>
而probaly形式有novalidate
属性。形式为required
的任何表单元素验证属性(如regexp
或novalidate attribute)都将忽略。
检查textarea中的默认值。必须有空格被视为值。
我遇到了类似的问题。我在Textarea的开始和结束标记之间留下了空格,如下面的代码所示
<label><b>Register As:*</b></label>
<select name="category" id="category" class="form-control"
onchange="toggleInput()" required>
<option value=''>--Select--</option>
<option value='Attendee'>Attendee</option>
<option value='Presenter'>Presenter</option>
</select>
...
<textarea name="description" id="description" class="form-control"
placeholder="Explain here what you will present..."> </textarea>
并在我的JavaScript中我试图跟随
<script>
function toggleInput() {
if( document.getElementById("category").value=="Attendee"){
document.getElementById("description").required = false;
}
else{
document.getElementById("description").required = true;
}
}//End Function
</script>
在我登陆这个页面之前,我无法弄清楚问题是什么。这是空间。谢谢@sinisake的解决方案。希望分享我的经验会有所帮助