我为我的ASP.net页面制作了脚本,以验证几个文本框的值。问题是,有时脚本工作,有时不工作。这是我的剧本:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript"></script>
<script>
$(document).ready(function () {
var _t1 = $(document.getElementById("<%=textbox5.ClientID%>"));
var _t2 = $(document.getElementById("<%=textbox4.ClientID%>"));
var _t3 = $(document.getElementById("<%=textbox10.ClientID%>"));
var _t4 = $(document.getElementById("<%=textbox9.ClientID%>"));
var _t5 = $(document.getElementById("<%=textbox15.ClientID%>"));
var _t6 = $(document.getElementById("<%=textbox14.ClientID%>"));
var _tLabel = $(document.getElementById("<%=IsMatch.ClientID%>"));
if (_t1.val() < _t2.val()) {
$(_tLabel).fadeIn('fast');
$(_tLabel).html('ERROR ');
$("#tg-yw4l-1").css("background-color", "red");
}
else if (_t3.val() < _t4.val()) {
$(_tLabel).fadeIn('fast');
$(_tLabel).html('ERROR');
$("#tg-yw4l-2").css("background-color", "red");
}
else if (_t5.val() < _t6.val()) {
$(_tLabel).fadeIn('fast');
$(_tLabel).html('ERROR');
$("#tg-yw4l-3").css("background-color", "red");
}
else {
$(_tLabel).fadeOut('fast');
}
});
</script>
有时候如果遇到错误要求,它就不会显示错误信息并改变背景。