JavaScript-input标签添加必填校验
源
1 2 3 4 5 6 | <div class= "form-group has-error has-feedback" > <label class= "control-label" for = "inputError2" >Input with error< /label > <input type = "text" class= "form-control" id = "inputError2" aria-describedby= "inputError2Status" > <span class= "glyphicon glyphicon-remove form-control-feedback" aria-hidden= "true" >< /span > <span id = "inputError2Status" class= "sr-only" >(error)< /span > < /div > |
例:
1 2 3 4 5 6 7 | <div class= "form-group" > <label class= "control-label" for = "taskName" style= "display: none" >不能为空!< /label > <input type = "text" class= "form-control" name= "taskName" id = "taskName" aria-describedby= "inputError2Status" /> <%--<input type = "text" class= "form-control" id = "inputError2" aria-describedby= "inputError2Status" >--%> <span class= "glyphicon glyphicon-remove form-control-feedback" aria-hidden= "true" >< /span > <span id = "inputError2Status" class= "sr-only" >(error)< /span > < /div > |
,,,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function isRequired(){ var flag = false ; $( ".control-label" ).each( function (){ var inputval = $( "#" +$(this).attr( "for" )+ "" ).val(); if (inputval==null||inputval== "" ||inputval==undefined){ $(this).attr( "style" , "display:show" ); $( "#" +$(this).attr( "for" )+ "" ).parent().attr( "class" , "form-group has-error has-feedback" ); //alert ( false ); flag = false ; } else { $(this).attr( "style" , "display:none" ); $( "#" +$(this).attr( "for" )+ "" ).parent().attr( "class" , "form-group " ); //alert ( true ); flag = true ; } }); return flag; } |
分类:
JavaScript
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库