【问题标题】:Text area placeholder is not showing up while having no space or newline between opening and closing tags文本区域占位符未显示,而开始和结束标记之间没有空格或换行符
【发布时间】:2021-09-16 23:22:52
【问题描述】:

我的文本区域占位符未显示。 我在这里看到的所有以前的答案都描述了文本区域的开始和结束标记之间不应该有空格或换行符,而我的代码没有两者。data-validation-required-message 是在制造问题吗?我该如何解决这个问题。
这是我的代码:

                         <div class="col-md-6">
                            <div class="form-group">
                                <textarea class="form-control" placeholder="Your Message *"  id="message" required data-validation-required-message="Please enter a message."></textarea>
                                <p class="help-block text-danger"></p>
                            </div>

【问题讨论】:

  • 您想在 Textarea 中显示 Please enter a message,因此您可以使用 tooltip 是更好的选择
  • 您的代码是正确的。可能在 CSS 中,为 textarea 占位符字体颜色定义了一些属性。可能是因为这个原因占位符不可见。

标签: html css twitter-bootstrap-3


【解决方案1】:

我去试试

<textarea class="form-control" placeholder="Your Message *"  id="message" required data-validation-required-message="Please enter a message."></textarea>

但这对我有用!:S

【讨论】:

    【解决方案2】:

    这是工作的检查Sinppet

    演示:: https://reactiveraven.github.io/jqBootstrapValidation/

     $(function() {
    
                    prettyPrint();
    
                    $("input,textarea,select").jqBootstrapValidation(
                        {
                            preventSubmit: true,
                            submitError: function($form, event, errors) {
                                // Here I do nothing, but you could do something like display 
                                // the error messages to the user, log, etc.
                            },
                            submitSuccess: function($form, event) {
                                alert("OK");
                                event.preventDefault();
                            },
                            filter: function() {
                                return $(this).is(":visible");
                            }
                        }
                    );
    
                    $("a[data-toggle=\"tab\"]").click(function(e) {
                        e.preventDefault();
                        $(this).tab("show");
                    });
    
                });
            <link rel="stylesheet" href="https://reactiveraven.github.io/jqBootstrapValidation/css/prettify_bootstrap.css">
            <link rel="stylesheet" href="https://reactiveraven.github.io/jqBootstrapValidation/css/bootstrap.css">
            <script src="https://reactiveraven.github.io/jqBootstrapValidation/js/jQuery-1.7.2-min.js"></script>
            <script src="https://reactiveraven.github.io/jqBootstrapValidation/js/bootstrap.js"></script>
            <script src="https://reactiveraven.github.io/jqBootstrapValidation/js/prettify.js"></script>
            <script src="https://reactiveraven.github.io/jqBootstrapValidation/js/jqBootstrapValidation.js"></script>
    
    
    
    <form class="form-horizontal" novalidate>
                            <div class="control-group">
                                <label class="control-label" for="email">Email address</label>
                                <div class="controls">
                                    <input type="email" name="email" id="email" required>
                                    <p class="help-block">Email address we can contact you on</p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="emailAgain">Email again</label>
                                <div class="controls">
                                    <input type="email" data-validation-matches-match="email" data-validation-matches-message="Must match email address entered above" id="emailAgain" name="emailAgain">
                                    <p class="help-block">And again, to check for speeling miskates</p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="terms-and-conditions">Legal</label>
                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" id="terms-and-conditions" name="terms-and-conditions" required data-validation-required-message="You must agree to the terms and conditions">
                                        I agree to the <a href="#">terms and conditions</a>
                                    </label>
                                    <p class="help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">Quality Control</label>
                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" name="qualityControl[]" value="fast" data-validation-minchecked-minchecked="2" data-validation-minchecked-message="Choose two" data-validation-maxchecked-maxchecked="2" data-validation-maxchecked-message="You can't have it all ways" >
                                        Fast
                                    </label>
                                    <label class="checkbox">
                                        <input type="checkbox" name="qualityControl[]" value="cheap">
                                        Cheap
                                    </label>
                                    <label class="checkbox">
                                        <input type="checkbox" name="qualityControl[]" value="good">
                                        Good
                                    </label>
                                    <p class="help-block"></p>
                                </div>
                            </div>
                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary">Test Validation <i class="icon-ok icon-white"></i></button><br />
                             
                            </div>
                        </form>

    注意:


    现在,如果您想显示此消息Please enter a message.,那么您必须使用 Jquery 进行验证。因为它的data-validation-required-message 用于显示自定义验证消息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      • 2015-08-20
      • 2016-05-24
      相关资源
      最近更新 更多