$(...)。jqBootstrapValidation不是HTMLDocument上的函数。<匿名>

时间:2019-07-16 11:30:22

标签: asp.net twitter-bootstrap jqbootstrapvalidation

我正在尝试使用引导程序模板来实现“与我们联系”页面。我是asp.net的真正初学者,也是我第一次使用模板。     我真的不能得到它在哪里导致上述错误的问题。 我想当用户单击发送消息按钮将电子邮件发送到当前的企业电子邮件时。     谁能帮我吗?

contact.cshtml

        <div class="row">
            <div class="col-lg-8 mb-4">
                <h3>Send us a Message</h3>
                <form name="sentMessage" id="contactForm" novalidate>
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Full Name:</label>
                            <input type="text" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
                            <p class="help-block"></p>
                        </div>
                    </div>
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Phone Number:</label>
                            <input type="tel" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number.">
                        </div>
                    </div>
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Email Address:</label>
                            <input type="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address.">
                        </div>
                    </div>
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Message:</label>
                            <textarea rows="10" cols="100" class="form-control" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
                        </div>
                    </div>
                    <div id="success"></div>
                    <!-- For success/fail messages -->
                    <button type="submit" class="btn btn-primary" id="sendMessageButton">Send Message</button>
                </form>
            </div>     
        </div>
    </div>

    <script src="~/Content/vendor/jquery/jquery.min.js"></script>        
    <script src="~/Scripts/contact_me.js"></script>
    <script src="~/Scripts/jqBootstrapValidation.js"></script>
    <script src="~/Content/vendor/bootstrap/js/bootstrap.min.js"></script>



    contact_me.js

    $(function () {

      $('#contactForm input,#contactForm textarea').jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
          // additional error messages or events
        },
        submitSuccess: function($form, event) {
          event.preventDefault(); // prevent default submit behaviour
          // get values from FORM
          var name = $("input#name").val();
          var email = $("input#email").val();
          var phone = $("input#phone").val();
          var message = $("textarea#message").val();
          var firstName = name; // For Success/Failure Message
          // Check for white space in name for Success/Fail message
          if (firstName.indexOf(' ') >= 0) {
            firstName = name.split(' ').slice(0, -1).join(' ');
          }
          $this = $("#sendMessageButton");
          $this.prop("disabled", true); // Disable submit button until AJAX call is complete to prevent duplicate messages
            $.ajax({
                     url: "mail/contact_me.php",
            type: "POST",
            data: {
              name: name,
              phone: phone,
              email: email,
              message: message
            },
            cache: false,
            success: function() {
              // Success message
              $('#success').html("<div class='alert alert-success'>");
              $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                .append("</button>");
              $('#success > .alert-success')
                .append("<strong>Your message has been sent. </strong>");
              $('#success > .alert-success')
                .append('</div>');
              //clear all fields
              $('#contactForm').trigger("reset");
            },
            error: function() {
              // Fail message
              $('#success').html("<div class='alert alert-danger'>");
              $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                .append("</button>");
              $('#success > .alert-danger').append($("<strong>").text("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!"));
              $('#success > .alert-danger').append('</div>');
              //clear all fields
              $('#contactForm').trigger("reset");
            },
            complete: function() {
              setTimeout(function() {
                $this.prop("disabled", false); // Re-enable submit button when AJAX call is complete
              }, 1000);
            }
          });
        },
        filter: function() {
          return $(this).is(":visible");
        },
      });

      $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
      });
    });

    /*When clicking on Full hide fail/success boxes */
    $('#name').focus(function() {
      $('#success').html('');
    });

1 个答案:

答案 0 :(得分:0)

我的回答随着评论的变化而变化:

  

答案是OP两次添加了Jquery,从而在   文件enter code here import numpy as np clrs = np.linspace( 0, 1, 18 ) # It will generate # color only for 18 for more change the number np.random.shuffle(clrs) colors = [] for i in range(0, 72, 4): idx = np.arange( 0, 18, 1 ) np.random.shuffle(idx) r = clrs[idx[0]] g = clrs[idx[1]] b = clrs[idx[2]] a = clrs[idx[3]] colors.append([r, g, b, a])

另外,为了帮助基于OP的帖子的其他人,下一部分也可能会有所帮助:

Javascript文件需要按照其依赖顺序进行加载。由于您的自定义JavaScript文件jqBootstrapValidation.js取决于javascript文件contact_me.js中包含的功能,因此您需要在jqBootstrapValidation.js之前加载jqBootstrapValidation.js,以解决此切换的顺序这些文件已加载:

contact_me.js