首先呢,说一下,刚学jQuery一天,身边没有老师,虽然这手册是最好的老师,不过不能说话,下面是我根据手册上说的,写出来的代码,但是运行不对的,因为没有button。我主要想请达人们讲下,这个button怎么写,简单的说就是如何完善这个程序;并且,请附带讲一下那个“toggle(flip++%2==0);”实现了什么样的功效,是如何操作的。 谢谢。<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="F:/WEB/JQuery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
  var flip=0;
  $("button").click(function(){
   $("p").toggle(flip++%2==0);
  });
});
</script>
</head><body>
<p style="display:none">HELLO</p>
<p style="display:block">HELLO AGAIN</p>
</body>
</html>

解决方案 »

  1.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
            <script type="text/javascript">
                $(function(){
    var flip = 0;
                    $(":input[name='but_name']").click(function(){
    $('p').toggle(flip++ %2 == 0);
    //toggle():显示或者隐藏,如果现在是显示,再点击就隐藏,否则反之
    //flip++ %2 == 0 :判断条件
    });
                });
            </script>
    </head>
    <body>
    <p style="display:none">HELLO</p>
    <p style="display:block">HELLO AGAIN</p>
    <input type="button" name="but_name" value="button">
    </body>
    </html>