我已经在WordPress中构建了一个主题,它运行正常,但我无法让Twitter Bootstrap验证工作,现在已经卡住了几个星期。 这里是functions.php文件夹:
<?php
add_theme_support( 'post-thumbnails' ); //Adds thumbnails compatibility to the theme
// set_post_thumbnail_size( 250, 250 ); // 50 pixels wide by 50 pixels tall, resize mode
function dsm_portfolio_styles() {
wp_enqueue_style('bootstrap_css', get_template_directory_uri() . '/vendor/bootstrap/css/bootstrap.min.css');
wp_enqueue_style('style.css', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'dsm_portfolio_styles');
function dsm_javascript_scripts() {
wp_enqueue_script('bootstrap_js', get_template_directory_uri() . '/vendor/bootstrap/js/bootstrap.min.js', array('jquery'), '', true);
wp_enqueue_script('jqBootstrapValidation', get_template_directory_uri() . '/js/jqBootstrapValidation.js', array('jquery'), '', true );
wp_enqueue_script('contact_me', get_template_directory_uri() . '/js/contact_me.js', array('jquery'), '', true );
wp_enqueue_script('freelancer', get_template_directory_uri() . '/js/freelancer.min.js', array('jquery'), '', true );
wp_enqueue_script('scrollspy', get_template_directory_uri() . '/js/scrollspy.js', array('jquery'), '', true );
}
add_action('wp_enqueue_scripts', 'dsm_javascript_scripts');
并在index.php页面上形成:
<!-- Contact Section -->
<section id="Contact">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Contact Me</h2>
<hr class="star-primary">
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<!-- To configure the contact form email address, go to mail/contact_me.php and update the email address in the PHP file on line 19. -->
<!-- The form should work on most web servers, but if the form is not working you may need to configure your web server differently. -->
<form name="sentMessage" id="contactForm" novalidate action="http://formspree.io/daniel@mobbzys.co.uk" method="POST">
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label for="email">Email Address</label>
<input name="email" type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label for="phone">Phone Number</label>
<input name="phone" type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label for="message">Message</label>
<textarea name="message" rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-success btn-lg">Send</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
答案 0 :(得分:0)
你应该在页脚中添加这个脚本。
<script>
$(function () { $("input,select,textarea").not("type=submit]").jqBootstrapValidation(); } );
</script>