【发布时间】:2019-04-25 14:47:40
【问题描述】:
我有这些文本框和选择框,我需要在单击按钮时验证是否有输入。我需要空白文本框是红色的,就像在我的选择下拉列表中一样。输入输入后,红色标记怎么会消失?请帮忙
$(document).ready(function() {
$('#add').on('click', function() {
bootstrap_alert('PLEASE FILL IN VALUES');
});
bootstrap_alert = function(message) {
var uname = $("#uname").val();
var age = $("#age").val();
var sex = $("#sex").val();
if (uname.length == 0 || age.length == 0 || sex.index == 0) {
$('#alert_placeholder').html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><span>' + message + '</span></div>')
$("#uname").css({
"background-color": "#ff3300"
});
$("#age").css({
"background-color": "#ff3300"
});
$("#sex").css({
"background-color": "#ff3300"
});
} else {
$('#alert_placeholder').html('');
}
}
});
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.11.0.js'></script>
<div id="alert_placeholder"></div>
Name: <input type="text" id="uname" /> Age: <input type="text" id="age" /> Sex:
<select id="sex" name="sex" />
<option value="" selected="selected"> Please Select </option>
<option value="Male"> Male </option>
<option value="Female"> Female </option>
</select>
<input type="button" id="add" value="Add">
【问题讨论】:
-
设置背景色为空字符串。
-
还是不行
标签: javascript jquery html drop-down-menu