jquery - css 中的表单验证无法正常工作

标签 jquery html css twitter-bootstrap

我创建了一个注册 html 页面,我试图在其中基于表单验证向文本字段添加效果。

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="css/bootstrap.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="css/bootstrap-theme.css">

        <script src="js/jquery.js"></script>
        <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">
        <!-- Latest compiled and minified JavaScript -->
        <script src="js/bootstrap.js"></script>
        <!-- <script src="js/FormValidation.js"></script> -->
        <script src="https://use.fontawesome.com/b1af24592c.js"></script>
    </head>
    <body>
        <div>
                <div class="col-md-3">
                </div>
                <div class="col-md-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 style="text-align:center"><a style="text-decoration:none; color:#000000;" href="index.html">Form</a></h3>
                        </div>
                        <div class="panel-body">
                            <form>
                                <div class="form-group has-feedback has-warning">
                                    <label>First Name</label>
                                    <input type="text" placeholder="Your first name" class="form-control" id="firstName" required>
                                    <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
                                </div>
                                <div class="form-group has-feedback has-success">
                                    <label>Last Name</label>
                                    <input type="text" placeholder="Your last name" class="form-control" id="lastName" required>
                                    <span class="glyphicon glyphicon-ok form-control-feedback"></span>
                                </div>
                                <div class="form-group">
                                    <label>Email</label>
                                    <input type="text" placeholder="Your email id" class="form-control" id="email" required>
                                </div>
                                <div class="form-group">
                                    <label>Password</label>
                                    <input type="password" placeholder="Password" class="form-control" id="password" required>
                                </div>
                                <div class="form-group">
                                    <label>Confirm Password</label>
                                    <input type="password" placeholder="Confirm your password" class="form-control" id="confirmPassword" required>[![enter image description here][1]][1]
                                </div>
                            </form>
                        </div>
                        <div class="panel-footer">
                            <button class="btn btn-info btn-block">Register</button>
                            <h6>Already a user? <a href="#" data-toggle="modal" data-target="#modal-signin">Sign In</a></h6>
                        </div>
                    </div>
                </div>
        </div>
    </body>
</html>

在页面中,我想在文本框中添加 glyphicon-ok 和 glyphicon-warning。

像这样

enter image description here

但我得到的是这个:

enter image description here

如何解决这个问题?

最佳答案

你必须将类放在 label 上,并将 inputicon span 放入 div 中,如下所示:

<div class="form-group has-feedback">
        <label for="fname" class="control-label col-md-6">First Name:</label>
        <div class="col-md-6">
            <input type="text" name="fname" id="fname" class="form-control" placeholder="Enter first name" />
            <span class="glyphicon form-control-feedback" id="fname1"></span>
       </div>
    </div>

FIDDLE

希望它能解决您的问题。

关于jquery - css 中的表单验证无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45073040/

相关文章:

javascript - 单击内部标签时将类添加到 li

jquery - 自定义添加的顶级菜单项的事件状态 [Magento topmenu]

html - 如何将具有大量文本的相关元素放置在不那么高的元素旁边,向左浮动

html - 将 block 元素固定到屏幕底部的中心?

jquery - 查找字体大小大于指定的元素

html - 设置过渡持续时间后无法覆盖打印样式中的填充

javascript - Angular 内联编辑表单例

jquery - 如何制作以Flipkart或Amazon相同的方式加载的Web应用程序?

影响 WordPress 菜单的 jQuery slider

javascript - 将文本字段元素添加到 div 的样式