刚用jquery遇到了这个问题,click没有反应。
jquery是这样的
<script type="text/javascript">
$(document).ready(function(){     
alert("1");
$("#b01").click(function(){
    alert("2");
});
});     
</script>这个是按钮<button id="b01" type="button">Change Content</button>页面刷新是会弹出 1 这个框,但是点击按钮 2 的框不但出来,没有反应,这时为什么啊!!

解决方案 »

  1.   

    光光这部分代码在FF下没有问题,估计是<button id="b01" type="button">Change Content</button>
    这部分你后面生成的,$(document).ready时还没加载这部分。
      

  2.   

    经测试正常<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title> new document </title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> </head><body>
    <script type="text/javascript">
    $(document).ready(function(){     
    alert("1");
    $("#b01").click(function(){ 
        alert("2");
    });
    });     
    </script>
    这个是按钮<button id="b01" type="button">Change Content</button>
    </body>
    </html>
      

  3.   

    <button id="b01" type="button">Change Content</button>是直接写在body里面的,这样也没加载到的吗?
    如果是没加载的问题,那有什么办法可以解决啊?
      

  4.   

    直接写在html里的话,你查一下是不是拼写错误什么的,独立的测试如2#,是可以运行的。
      

  5.   

    <%@ page contentType="text/html;charset=gbk"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <%@ page import = "java.util.*"  %>
    <%@ page import = "com.scnudims.model.*"  %>
    <!Doctype html public "-//w3c//dtd html 4.01 transitional//en" 
    "http://www.w3c.org/tr/1999/rec-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <style type="text/css">
    <!--
    .STYLE1 {
    font-size: medium
    }
    -->
    </style>
    <link rel="stylesheet" href="css/style.css" type="text/css" />
    <script type="text/javascript"  src="js/jquery-1.8.3.js"></script>
    <!--[if IE 7]><style>#dropdownMenu li ul ul {margin-left: 100px;}</style><![endif]-->
    </head>
    <body>
    <script type="text/javascript">
    $(document).ready(function(){     
    alert("1");
    $("#b01").click(function(){
        alert("2");
    });
    });     
    </script>
    <div id="container">
    <div id="wrapper">
    <jsp:include page="head.jsp"></jsp:include>
    <div id="header">
    <div class="intro"> <form method="get" id="searchform" action="#">
    <div>

    <input class="searchField" type="text" value="" name="q" />
    <input class="searchSubmit" type="submit" value="" />
    <input type="hidden" name="sitesearch" value="" />
    </div>
    </form>
    </div>
    </div>
    <div id="content">
    <button id="b01" type="button">Change Content</button>
    <form action="stmessageregister.action" method="post" name="stmessageregister" >                              
                     <label class="f2">收件人:</label>
                     <input type="text" name="stmessage.tname" size=20 id="tname" />
                     <div id="suggest"></div>
                     <br>
                     <textarea  name="stmessage.message" cols="90" rows="10" class="text" id="message"></textarea><br>
                     <input type="submit" name="submit" class="button1" value="发送" />
                     <br/>
                     </form> <big class="dwnld" style="padding-top: 10px;"><a href="#"></a>
    </big> <a class="backToTop" href="#">&nbsp;</a>
    </div>
    <div id="sidebar">
          <ul id="news">
            

            <li> <a href="#"> <img src="images/temp/news1.jpg" alt="" width="54" /> </a>
              <h3>News Heading H3</h3>
              <p>我们爱美女 <br />
                <a href="#">More &raquo;</a></p>
            </li>
            <li> <a href="#"> <img src="images/temp/news2.jpg" alt="" width="54" /> </a>
              <h3>News Heading H3</h3>
              <p>我们爱美女 <br />
                <a href="#">More &raquo;</a></p>
            </li>
            <li> <a href="#"> <img src="images/temp/news3.jpg" alt="" width="54" /> </a>
              <h3>News Heading H3</h3>
              <p>我们爱美女 <br />
                <a href="#">More &raquo;</a></p>
            </li>       
     </div>
    <jsp:include page="foot.jsp"></jsp:include>
    </div>
    </div>

    </body>
    </html>
    这个是我的页面,可以帮我看看问题出在哪吗?
      

  6.   

    去掉 jsp部分,可以执行啊。
      

  7.   

    把那个button换成
    <input type="button" id="b01" value="Change Content"/>
    试试button这个标签好像现在不大能正常用了。。
      

  8.   

    貌似去掉<jsp:include>的就行是里面的东西有冲突吗?
      

  9.   


    没有问题,FF,ie和谷歌都试过。你确定你按的是Change Content而不是《发送》?
      

  10.   

    有<jsp:include>部分就不行,删掉就可以了。是为什么呢?
      

  11.   


    那就可能是你include的部分也有个元素id叫b01,没记错的话ID选择器的话只会返回第一个元素。
      

  12.   

    貌似是有什么冲突了?$换成jQuery就行了,谢谢大家了