<script src="../JavaScript/jquery-2.0.2.min.js"></script> <script type="text/javascript"> //当光标离开文本框的时候如果文本框为空,则将文本框边框色设置为红色,如果不为空则为白色。提示:焦点进入控件的事件是focus或者mousedown,焦点离开控件的事件是blur。 $(function () { $("#txt_UID").focus(function () { if ($(this).val("必填")) { $(this).val(""); } }).blur(function () { if ($(this).val().length < 1) { $(this).val("(必填)"); $(this).css('border', '1px solid red'); } else { $(this).css('border', ''); } }); });//最后一个 </script>
转载于:https://www.cnblogs.com/ooip/p/4762621.html