1

私はJquery + Twitter Bootstrapを学んでおり、私が持っているモーダル内でボタンクリックイベントハンドラーを作成しようとしています。ただし、私のコードはこれを実装していません。

以下は私のindex.htmlです:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Online Calorie Tracker and Analyzer</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/modalHandler.js"></script>
  </head>
  <body>
    <div class="container">
      <h1>Calorie Tracker and Analyzer</h1>
          <div class="navbar">
              <div class="navbar-inner">
                <div class="container">
                  <ul class="nav">
                    <li class="active"><a href="index.html">Home</a></li>
                    <li><a href="#">Track Food</a></li>
                    <li><a href="#">Analyze Food</a></li>
                    </ul>
                </div>
              </div>
            </div>
      <div class="hero-unit">
    <h1>A healthy you begins with tracking and analysis</h1>
     <p>10 out of 10 doctors agree. Losing weight is healthy. With our online calorie tracker and analyzer, the power is in your hands!</p>
     <a href="#myModal" role="button" class="btn btn-danger" data-toggle="modal">Get Started</a>

     <!-- Modal -->
     <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <h3 id="myModalLabel">About Me</h3>
        </div>
  <div class="modal-body">
    <form id="statsForm" action="" method="get">
      Gender: <select id="gender">
          <option value="male">Male</option>
          <option value="female">Female</option>
          </select><br>
           Activity level: <select id="activity">
                       <option value="0">Sedentary (little or no exercise)</option>
               <option value="1">Lightly active (light exercise/sport 1-3 days/week)</option>
               <option value="2">Moderately active (moderate exercise/sports 3-5 days/week)</option>
               <option value="3">Very active (hard exercise/sports 6-7 days a week)</option>
               <option value="4">Extra active (very hard exercise/sports & physical job or 2x training)</option>
                       </select><br>
      Weight Loss Goal: <select id="lossGoal">
                        <option value=".5">Lose 0.5 lbs per week</option>
                <option value="1">Lose 1 lbs per week</option>
                <option value="1.5">Lose 1.5 lbs per week</option>
                <option value="2">Lose 2.0 lbs per week</option>
                        </select><br>
    </form>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary" id="modal-btn">Submit</button>
  </div>
</div>
 </div>
    </div>   
  </body>
<html>

これが私の Jquery スクリプト (「modalHandler.js」) です。

$(document).ready(function() {
    $("#myModal").on("click", "#modal-btn", function() {
    alert("hello world!");
    });
});

どんな助けでも大歓迎です!

4

0 に答える 0