4

I'm very new to coding, so bear with me. I've looked at a few of the answered posted for the same question, and have gotten the code to work while inputting my information in some of the solved jsfiddle links.

The problem is: When I plug the working code into my HTML and JS file, it doesn't seem to work. I've looked over my code and am not sure what's breaking it or why it's not showing. I was wondering if anyone could look at my code and tell me why?

The section I'm talking about is the Browse Menu and Menu Output sections. Basically, if you click an image (omnivore, vegetarian, healthy) in the browse menu navigation, the corresponding menu output will be shown.

I've also included my HTML and JS to this post. The styles and spacing are a little messed up right now since I've been tinkering with things in my Mark up. I also recently read that tables are bad, so I will be changing that in my html to unordered lists.

Thanks so much!

HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Spice Up Your Love Life: An Interactive Dating Experience</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="keywords" content="date, interactive, cooking, culinary, dating, couple, love, date ideas, vancouver, spice, love life, experience">
    <meta name="Spice Up Your Love Life" content="SpiceUpYourLoveLife.com is an interactive dating experience in which you and your date can cook a meal together. Eat your heart out!">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style2.css">
    <link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700' rel='stylesheet' type='text/css'>
        <style type="text/css">
        @font-face{ 
            font-family: "talldark";
            src: url('http://fontsforweb.com/public/fonts/383/talldark.eot');
            src: local("Tall Dark And Handsome Condensed"), url('http://fontsforweb.com/public/fonts/383/talldark.woff') format("woff"), url('http://fontsforweb.com/public/fonts/383/talldark.ttf') format("truetype");
        }
        .diettitle {
            font-family: "talldark";
            font-size: 6em;
            letter-spacing: 5px;
            color: #b5a839;
        }
        .testerz {
            font-family: "talldark";
            font-size: 1em;
            letter-spacing: 4px;
            color: #b5a839;
        }
    </style>
</head>
<body>

<header>
Spice Up Your Love Life: An Interactive Dating Experience
</header>

<div id="topnavcontainer">
    <table id="topnav">
        <tr>
            <td id="break"><a href="google.ca">Breakfast</a></td>
            <td id="lunch"><a href="google.ca">Lunch</a></td>
            <td id="dinner"><a href="google.ca">Dinner</a></td>
            <td id="appetizer"><a href="google.ca">Appetizer</a></td>
            <td id="desert"><a href="google.ca">Desert</a></td>
            <td id="snack"><a href="google.ca">Snack</a></td>
        </tr>
    </table>
</div>


    <table id="mainnav">
        <tr>
            <td id="home" class="bordernav"><a href="google.ca">Home</a></td>
            <td id="works" class="bordernav"><a href=".waves">How It Works</a></td>
            <td id="menu" class="bordernav"><a href="#diet">Menu</a></td>
            <td id="mainnavbordernone"></td>
            <td id="tips" class="bordernav"><a href="google.ca">Tips and Tricks</a></td>
            <td id="contact" class="bordernav"><a href="google.ca">Test Skills</a></td>
            <td id="share" class="bordernav"><a href="google.ca">Share</a></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td id="logo"><a href="test.html"><img src="images/logo.png" alt="Spice Up Your Love Life Logo" width="189" height="170"></a></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td id="spicetitle" class="title">SPICE</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td id="upyourtitle" class="title">UP  &nbsp;YOUR</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td id="lovelifetitle" class="title">LOVE LIFE</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>


    <div class="container">
    <!--SPLASH CONTENT-->
    <div class="content">
    <div id="leftgrid">
    <img src="images/block.jpg" width="300" height="184"><br>
    <p class="contentheader">HOW DOES IT WORK?</p><br>
    <p class="contentdescribed">Does it sound too good to be true? --- Well, it's not!  See how it works and and how it all started. </p>
    <p class="contentcalltoaction"><a href=".waves">See how it works</a></p>
    </div>

    <div id="middleleftgrid">
    <img src="images/block.jpg" width="300" height="184"><br>
    <p class="contentheader">WHAT'S FOR DINNER?</p><br>
    <p class="contentdescribed">Eat your heart out! Browse our menu and select what 
    you'd like to cook for your     special date. </p>
    <p class="contentcalltoaction"><a href="#diet">Look at the menu</a></p>
    </div>

    <div id="middlerightgrid">
    <img src="images/block.jpg" width="300" height="184"><br>
    <p class="contentheader">IMPRESS YOUR DATE!</p><br>
    <p class="contentdescribed">Don't get caught with your elbows on the table! 
    These tips will have them wanting seconds! </p>
    <p class="contentcalltoaction"><a href="google.ca">Learn tips and tricks</a></p>
    </div>

    <div id="rightgrid">
    <img src="images/block.jpg" width="300" height="184"><br>
    <p class="contentheader">GOT WHAT IT TAKES?</p><br>
    <p class="contentdescribed">Put your skills to the test! Take our multiple choice test to see what culinary level you're at!</p>
    <p class="contentcalltoaction"><a href="google.ca">Test your skills</a></p>
    </div>
    </div>


    <!-- HOW IT WORKS SECTION -->
    <div id="howitworkssec">
    <div class="waves"></div>
        <h3 class="headliners"><strong>How does it work?</strong></h3>
        <img src="images/silboth.png" alt="dating silhouette" width="875" height="499"> 
    </div>

    <div id="howdesdiv">
    <p id="simpleas">It's as simple as 1, 2, 3.</p>
    <p id="howdes">
            1. Do this thing and that blah blah<br>
            2. Then you do this lolol can you believez it?<br>
            3. I'll add the actual content when the site is finished.<br>
        </p>
        <a href="#diet" alt="Browse Menu">Let's begin!</a>
    </div>









<!--BROWSE MENU-->
<div id="diet">
 <h3 id="meal" class="headliners">Meal Type</h3>
    <p id="lefty" class="curly">{</p>
    <p id="righty" class="curly">}</p>
<div class="dietchoice"><a href="#meat"><img src="images/carnivoreb.png" alt="meat options" width="90" height="93" /><h3 class="testerz">Omnivore</h3></a></div>
<div class="dietchoice"> <a href="#veggie"><img src="images/vegetarianb.png" alt="meat options" width="90" height="93" /><h3 class="testerz">Vegetarian</h3></a> </div>    
<div class="dietchoice"> <a href="#healthy"><img src="images/healthyb.png" alt="meat options" width="90" height="34" /><h3 class="testerz">Healthy</h3></a> </div>     


<!--MENU OUTPUT-->
<div id="output">
    <div id="meat">
    <p class="diettypeheading">Magnificent Meat Dishes</p>
    <img src="images/centermeatballs.jpg" alt="meatballsplash" width="600" height="400" id="meatleft" >
    <img src="images/centerchicken.jpg" alt="meatballsplash" width="533" height="400" id="meatcenter">
    <img src="images/centersteak.jpg" alt="meatballsplash" width="529" height="400" id="meatright">
    </div>

    <div id="veggie">
    <p class="diettypeheading">Fresh, Colourful Dishes</p>
    <img src="images/centermeatballs.jpg" alt="meatballsplash" width="600" height="400" id="meatleft" >
    <img src="images/meatballs.jpg" alt="meatballsplash" width="533" height="400" id="meatcenter">
    <img src="images/centersteak.jpg" alt="meatballsplash" width="529" height="400" id="meatright">
    </div>      

    <div id="healthy">
    <p class="diettypeheading">Diabetic and Heart Healthy Meals</p>
    <img src="images/centermeatballs.jpg" alt="meatballsplash" width="600" height="400" id="meatleft" >
    <img src="images/centerchicken.jpg" alt="meatballsplash" width="533" height="400" id="meatcenter">
    <img src="images/meatballs.jpg" alt="meatballsplash" width="529" height="400" id="meatright">
    </div>          
</div>



     <!--END OF CONTENT-->  
    <div class="splashimage">
    <img src="images/banner3.png" alt="splash image" width="1664" height="400">
    </div>


    <div id="sitemap">
            <table class="sitemaptab">
  <tr id="sitemaptitles">
    <th>Get Social</th>
    <th>Quick Links</th>
    <th>Terms of Use</th>
  </tr>
    <tr id="row_two">
    <td class="social"><a href="twitter.com"><img src="images/socialmedia/twit_sm.png" alt="sm-twiticon">Follow Us On Twitter</a></td>
    <td class="quicklinks"><a href="#topnavcontainer">Home</a></td>
    <td class="terms"><a href="google.ca">Privacy Policy</a></td>
  </tr>
  <tr id="row_three">
    <td class="social"><a href="facebook.com"><img src="images/socialmedia/fb_sm.png" alt="sm-fbicon">Like Us On Facebook</a></td>
    <td class="quicklinks"><a href="#menudiv">Browse Menu</a></td>
    <td class="terms"><a href="google.ca">Contact</a></td>
  </tr>
    <tr>
    <td> </td>
    <td class="quicklinks"><a href=".waves">How It Works</a></td>
    </tr>
    <tr>
    <td></td>
    <td class="quicklinks"><a href="google.ca">Tips and Tricks</a></td>
    </tr>
    <tr>
    <td></td>
    <td class="quicklinks"><a href="google.ca">Share</a></td>
  </tr>
</table>
    </div>






<footer>
    <table id="footer">
        <tr>
            <td id="copyright">Copyright © Spice Up Your Love Life 2013</td>
            <td id="webdesby">Web Design By: <a href="http://google.ca">Ticking and Talking Media</a></td>
        </tr>
    </table>
</footer>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="js/spicelovelife.js"></script>
<script src="js/plugins.js"></script>
<script src="js/vendor/jquery-1.9.0.min.js"></script>
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
</body>
</html>

JavaScript:

// Scrolling Function
$('a').click(function(){
    $('html, body').animate({
        scrollTop: $( $(this).attr('href') ).offset().top
    }, 500);
    return false;
});

// Load All Images
$('body').waitForImages({
    waitForAll: true,
    finished: function() {
       // All images have loaded.
    }  
});


//Hide All Divs
$("#output > div").hide();

$(".dietchoice a").click(function(e) {
  $("#output div").hide();
  $(this.hash).show();
  e.preventDefault();
});
$("#areas div:not(#meat)").hide();
4

2 に答える 2

3

それ以外の

$(this.hash).show();

おそらく使用する必要があります

$(this.attr('href')).show();

this.hashhashプロパティが存在しないため、おそらく undefined が返されます。

私のソリューションが「undefined method attr()」のようなエラーをスローする場合は、おそらく jQuery セレクターを使用する必要があります。

$($(this).attr('href')).show();

デバッグ目的でコンソール オブジェクトを使用することをお勧めします。Mozilla Developer Networkでデバッグに関するドキュメントを見つけることができます。

このセレクターは、このセレクター$("#output > div")とは異なり$("#output div")ます。HTML によると、両方のセレクターが同じ要素を返しますが、HTML 構造を変更すると問題が発生する可能性があります。

于 2013-03-16T07:14:02.350 に答える
0

コードの前に modernizr、jquery、および plugin スクリプトを配置してみてください。つまり、これを変更します。

<script src="spicelovelife.js"></script>
<script src="js/plugins.js"></script>
<script src="js/vendor/jquery-1.9.0.min.js"></script>
<script src="js/vendor/modernizr-2.6.2.min.js"></script>

これに:

<script src="js/vendor/jquery-1.9.0.min.js"></script>
<script src="js/plugins.js"></script>
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
<script src="js/spicelovelife.js"></script>

この助けを願っています。

于 2013-03-16T07:46:40.150 に答える