如何使用jQuery修复搜索栏

时间:2019-03-27 12:57:45

标签: jquery wordpress woocommerce

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<?php
/**
 * The header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="content">
 *
 * @package storefront
 */

?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Lato|Montserrat|Open+Sans|Raleway" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">

<!-- SLider Home -->
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri();?>/assets/css/slider.css" />
<script type="text/javascript" src="<?php echo get_template_directory_uri();?>/assets/js/home-slider/modernizr.custom.28468.js"></script>
<script type="text/javascript" src="<?php echo get_template_directory_uri();?>/assets/js/signup-modal.js"></script>

<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.css"/>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick-theme.css"/>
<!-- Animate.css library -->
<link href="<?php echo get_template_directory_uri();?>/assets/css/animate.min.css" rel="stylesheet">


<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<?php if (!is_page_template( 'page-teste.php' )) { ?>
<div id="page" class="hfeed site">
	<?php
	do_action( 'storefront_before_header' ); ?>
    
	<header id="masthead" class="site-header" role="banner">
		<div class="header-wrap">
			<div class="top-header">
				<div class="top-header-wrap container auto-align">
					<div class="welcome header-left">Get in touch with us: <a href="mailto:info@thefuturefoods.com">info@thefuturefoods.com</a></div>
                    <div class="links header-right">
                        <a href="#" class="xoo-el-login-tgr">Login</a>
                        <a href="#" class="xoo-el-reg-tgr">Register</a>
                        <a href="#" class="xoo-el-myaccount-menu">My Account</a>
                        <a href="#" class="xoo-el-logout-menu">Logout</a>
                        <a href="javascript:void(0)" class="sign-up social-icon" onclick="openSignupNav()">Subscribe</a>
                        <a href="https://www.facebook.com/thefuturefoods/" target="_blank" class="social-icon"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                        <a href="#" class="social-icon"><i class="fa fa-instagram" aria-hidden="true"></i></a>
                        <a href="#" class="social-icon"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                        <a href="#" class="social-icon"><i class="fa fa-youtube" aria-hidden="true"></i></a>
                    </div>
				</div>
			</div>
			<?php $root = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; ?>
			<div class="main-header">
				<div class="main-header-wrap container auto-align">
					<div class="brand-logo header-left">
						<a href="<?php echo $root; ?>/new-shop/">
							<img src="<?php echo get_template_directory_uri().'/assets/images/tff_homepage/logo.png';?>" alt="The Future Foods">
						</a>
					</div>
					<div class="categories header-right">
						<ul class="categories-wrap">
							<li class="categories-link"><a href="<?php echo $root; ?>/new-shop">Home</a></li>
							<li class="categories-link"><a href="<?php echo $root; ?>/about-us/">About us</a></li>
							<li class="categories-link">
                                <a href="<?php echo $root; ?>/products">Products</a>
                                <ul class="sub-menu">
                                  <li class="categories-link"><a href="<?php echo $root; ?>/product-category/purees/">Purées</a></li>
                                  <li class="categories-link"><a href="<?php echo $root; ?>/product-category/soups/">Soups</a></li>
                                  <li class="categories-link">
                                      <a href="<?php echo $root; ?>/product-category/desserts/">Desserts</a>
                                      <ul class="sub-menu-child">
                                          <li class="categories-link"><a href="<?php echo $root; ?>/product-category/desserts/mousses/">Mousses</a></li>
                                          <li class="categories-link"><a href="<?php echo $root; ?>/product-category/desserts/gelatines/">Gelatines</a></li>
                                          <li class="categories-link"><a href="<?php echo $root; ?>/product-category/desserts/puddings">Puddings</a></li>
                                      </ul>
                                    </li>
                                  <li class="categories-link"><a href="<?php echo $root; ?>/product-category/dehydrated/">Dehydrated</a></li>
                                  <li class="categories-link"><a href="<?php echo $root; ?>/product-category/cereals/">Cereals</a></li>
                                  <li class="categories-link"><a href="<?php echo $root; ?>/product-category/sauces/">Sauces</a></li>
                                </ul>
                            </li>
							<li class="categories-link"><a href="<?php echo $root; ?>/naf/">NAF</a></li>
							<li class="categories-link"><a href="<?php echo $root; ?>/news-blog/">News & Blog</a></li>
							<li class="categories-link highlight"><span class="new_stamp flash">NEW</span><a data-popup-open="popup-1" href="#">Catalogue</a></li>
							<li class="categories-link">
                                <form role="search" method="get" class="search-form" action="<?php echo $root; ?>">
                                    <label id="search-label" >
                                        <span class="screen-reader-text">Search for:</span>
                                        <input type="search" class="search-field" placeholder="Search …" value="" name="s" style="background: #f2f5f8; box-shadow: none; border: none;">
                                    </label>
                                    <button type="submit" class="search-submit" value="Search" style="display:none"><i class="fa fa-search"></i></button>
                                </form>
                                <a href="#" class="search-submit"><i class="fa fa-search"></i></a>
                            </li>
                            <li class="categories-link">
                                <?php if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
                                    $count = WC()->cart->get_cart_contents_count();
                                    ?>
                                    <?php if ( $count > 0 ) { ?>
                                        <a class="cart full" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>">
                                            <i class="fa fa-shopping-cart" aria-hidden="true"></i>
                                        </a>
                                    <?php } else { ?>
                                        <a class="cart empty" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'Your cart is empty' ); ?>">
                                            <i class="fa fa-shopping-cart" aria-hidden="true"></i>
                                        </a>    
                                    <?php } ?>

                                <?php } ?>
                            </li>
                            <li class="categories-link">
                                <a href="#" class="mobile-menu" onclick="openNav()" style="margin-left: 5px; border-radius: 50%; padding: .9em 1.4em; border: 1px solid #000"><i class="fa fa-bars"></i></a>
                            </li>
						</ul>
					</div>
				</div>
			</div>
			<div id="mySidenav" class="sidenav">
              <a href="javascript:void(0)" class="closebtn" onclick="closeNav()"><i class="fa fa-long-arrow-left" aria-hidden="true"></i></a>
              <ul class="cd-accordion-menu">
            	<li><a href="http://www.thefuturefoods.com/new-shop/">Home</a></li>
            	<li><a href="http://www.thefuturefoods.com/about-us/">About us</a></li>
            	<li class="has-children">
            		<input type="checkbox" name ="group-1" id="group-1">
            		<label for="group-1">Products</label>
             
              		<ul>
              			<li><a href="http://www.thefuturefoods.com/product-category/purees/">Purées</a></li>
            			<li><a href="http://www.thefuturefoods.com/product-category/soups/">Soups</a></li>
              			<li class="has-children">
              				<input type="checkbox" name ="sub-group-1" id="sub-group-1">
            				<label for="sub-group-1">Desserts</label>
             
            				<ul>
            					<li><a href="http://www.thefuturefoods.com/product-category/mousses/">Mousses</a></li>
            					<li><a href="http://www.thefuturefoods.com/product-category/gelatines/">Gelatines</a></li>
            					<li><a href="http://www.thefuturefoods.com/product-category/puddings/">Puddings</a></li>
            				</ul>
              			</li>
              			<li><a href="http://www.thefuturefoods.com/product-category/dehydrated/">Dehydrated</a></li>
            			<li><a href="http://www.thefuturefoods.com/product-category/cereals/">Cereals</a></li>
            			<li><a href="http://www.thefuturefoods.com/product-category/sauces/">Sauces</a></li>
              		</ul>
            	</li>
            	<li><a href="http://www.thefuturefoods.com/naf/">NAF</a></li>
            	<li><a href="http://www.thefuturefoods.com/news-blog/">News & Blog</a></li>
            </ul> <!-- cd-accordion-menu -->
            <div class="brand-info">
                <div class="title">Get in touch with us</div>
                <span class="footer-cont">+351 936 432 518 / +351 229 826 028</span>
                <span><a href="mailto:info@thefuturefoods.com" class="footer-mail footer-cont">info@thefuturefoods.com</a></span>
                <div class="address footer-cont">
    	            Rua Serafim Cruz, 743&nbsp;<br>
    	            4475-669 Santa Maria Avioso&nbsp;<br>
    	            Castelo da Maia<br>
    	            Porto . Portugal
    	        </div>
            </div>
            <div class="social">
                <div class="social-wrapper">
                    <div class="social-links">
                        <a href="https://www.facebook.com/thefuturefoods/" target="_blank" class="social-icon"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                        <a href="#" class="social-icon"><i class="fa fa-instagram" aria-hidden="true"></i></a>
                        <a href="#" class="social-icon"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                        <a href="#" class="social-icon"><i class="fa fa-youtube" aria-hidden="true"></i></a>
                    </div>
                </div>
            </div>
            </div>
		</div>
	</header><!-- #masthead -->

	<?php if (!is_page_template( 'shop-v2.php' ) && !is_page_template( 'about.php' ) && !is_page_template( 'naf.php' )) { ?>
    <div class="breadcrumb-pagetitle">
		<div class="breadcrumb-pagetitle-wrap container auto-align">
			<div class="page-title header-left">
				<h1 class="title">
                    <?php if (is_singular() && get_post_type() == 'product')
                            the_title();
                          else if (is_singular() && get_post_type() == 'post')
                            echo "News & Blog";
                          else if (is_product_category())
                            woocommerce_page_title();
                          else if (is_search())
                            echo "Search";
                          else
                            the_title();
                    ?>
                </h1>
			</div>
			<div class="breadcrumb header-right">
				<?php
					 /**
            		 * Functions hooked in to storefront_content_top
            		 *
            		 * @hooked woocommerce_breadcrumb - 10
            		 */
            		 //do_action( 'storefront_content_top' );
            		 
            		
                    if ( function_exists('yoast_breadcrumb') ) {
                    yoast_breadcrumb('
                    <p id="breadcrumbs" class="woocommerce-breadcrumb">','</p>
                    ');
                    }
                   
				?>
			</div>
		</div>
	</div>
    <?php } else if (is_page_template( 'about.php' )) { ?>
        <div class="section about-header">
            <div class="header-wrap">
                <h1 class="title">About us</h1>
            </div>
        </div>
    <?php } else if (is_page_template( 'naf.php' )) { ?>
        <div class="section naf-header">
            <div class="header-wrap container auto-align">
                <div class="title-wrapper">
                    <h1 class="title">Natural</h1>
                    <h1 class="title"><span>Adapted</span> Food</h1>
                    <h1 class="title mobile">Natural Adapted Food</h1>
                </div>
                <div class="desc">The Future Foods has a range of Natural Adapted Food (NAF) that is specifically designed <span style="color:#049BD8; font-weight: 600;">for people unable to eat in a traditional way</span> (with chewing and swallowing difficulties).</div>
            </div>
            <div class="arrow-down animated bounce"><i class="fas fa-chevron-circle-down"></i></div>
        </div>
    <?php } else { ?>
        <?php //get_template_part('assets/backfiles/slider'); ?>
        <?php get_template_part('assets/backfiles/slick-slider'); ?>
    <?php } ?>

	<?php
	/**
	 * Functions hooked in to storefront_before_content
	 *
	 * @hooked storefront_header_widget_region - 10
	 */
	do_action( 'storefront_before_content' ); ?>

	<div id="content" class="site-content" tabindex="-1">
		<div class="container">

		<?php
		/**
		 * Functions hooked in to storefront_content_top
		 *
		 * @hooked woocommerce_breadcrumb - 10
		 */
		// 	do_action( 'storefront_content_top' );
} ?>
<script>
    function openNav() {
        if( /Android|webOS|iPhone|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
            document.getElementById("mySidenav").style.width = "100vw";
        } else {
            document.getElementById("mySidenav").style.width = "350px";
        }
    }

    function closeNav() {
        document.getElementById("mySidenav").style.width = "0";
    }
</script>            
<script>
jQuery(document).ready(function() {
    jQuery('.search-submit').on('mouseover', function(e) {
            e.preventDefault();
            if (!jQuery('.search-form').hasClass("active")){
                jQuery('.search-submit').find("i").removeClass("fa-search");
                jQuery('.search-submit').find("i").addClass("fa-arrow-left");
            }
    });
    jQuery('.search-submit').on('mouseout', function(e) {
            e.preventDefault();
			jQuery('.search-submit').find("i").removeClass("fa-arrow-left");
            jQuery('.search-submit').find("i").addClass("fa-search");
    });
    jQuery('.search-submit').on('click', function(e) {
            e.preventDefault();
            if(jQuery('.search-form').hasClass("active")){
                jQuery('.search-form').removeClass("active");
                jQuery('.search-submit').find("i").removeClass("fa-times");
                jQuery('.search-submit').find("i").addClass("fa-search");
            } else {
                jQuery('.search-form').addClass("active");
                jQuery('.search-submit').find("i").removeClass("fa-arrow-left");
                jQuery('.search-submit').find("i").addClass("fa-times");
            }
			jQuery('#search-label').animate({
                width: 'toggle',
            }).focus();
    });
    jQuery('#search-field').keypress(function (e) {
      if (e.which == 13) {
        $('.search-form').submit();
        return false;    //<---- Add this line
       }
    });
    
});
</script>

我的搜索栏没有显示产品,我可以按“输入”来进行搜索,而所做的只是“关闭”“悬停”功能。 该网站是:www.thefuturefoods.com 请考虑到这不是我开发的。我是目前正在为此工作的人。

<script>
jQuery(document).ready(function() {
    jQuery('.search-submit').on('mouseover', function(e) {
            e.preventDefault();
            if (!jQuery('.search-form').hasClass("active")){
                jQuery('.search-submit').find("i").removeClass("fa-search");
                jQuery('.search-submit').find("i").addClass("fa-arrow-left");
            }
    });
    jQuery('.search-submit').on('mouseout', function(e) {
            e.preventDefault();
            jQuery('.search-submit').find("i").removeClass("fa-arrow-left");
            jQuery('.search-submit').find("i").addClass("fa-search");
    });
    jQuery('.search-submit').on('click', function(e) {
            e.preventDefault();
            if(jQuery('.search-form').hasClass("active")){
                jQuery('.search-form').removeClass("active");
                jQuery('.search-submit').find("i").removeClass("fa-times");
                jQuery('.search-submit').find("i").addClass("fa-search");
            } else {
                jQuery('.search-form').addClass("active");
                jQuery('.search-submit').find("i").removeClass("fa-arrow-left");
                jQuery('.search-submit').find("i").addClass("fa-times");
            }
            jQuery('#search-label').animate({
                width: 'toggle',
            }).focus();
    });
    jQuery('#search-field').keypress(function (e) {
      if (e.which == 13) {
        $('.search-form').submit();
        return false;    //<---- Add this line
       }
    });

});
</script>

我希望它可以向我显示我搜索的产品,但目前未显示任何内容。

0 个答案:

没有答案