<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script src="lib/jquery/jquery-1.3.2.js">
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>jquery2.1</title>
        <script>
            function showjQueryObjectMethod(){
                alert("标签的数量为:" + $('#form1 *').length + "   \r\n\r\n标签的内容为:" + $('#form1 *').html());
            }
        </script>
    </head>
    <body>
        <form id="form1" name="form1" method="post" action="">
            <p>
                username:<input type="text" name="username" id="username" />
                <br/>
                password:<input type="password" name="password" id="password" />
                <br/>
                <input type="button" name="button" id="button" value="显示" onclick="showjQueryObjectMethod()"/>
            </p>
        </form>
    </body>
</html>
alert()中没有P啊,,,我晕了,

解决方案 »

  1.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
        <head> 
            <script src="lib/jquery/jquery-1.3.2.js"> 
            </script> 
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
            <title>jquery2.1 </title> 
            <script> 
                function showjQueryObjectMethod(){ 
                    alert("标签的数量为:" + $('#form1').length + "  \r\n\r\n标签的内容为:" + $('#form1 *').html()); 
                } 
            </script> 
        </head> 
        <body> 
            <form id="form1" name="form1" method="post" action=""> 
                <p> 
                    username: <input type="text" name="username" id="username" /> 
                    <br/> 
                    password: <input type="password" name="password" id="password" /> 
                    <br/> 
                    <input type="button" name="button" id="button" value="显示" onclick="showjQueryObjectMethod()"/> 
                </p> 
            </form> 
        </body> 
    </html> 
    加*了就是拿P里的对象了.
      

  2.   

    $('#form1 *').html() 改为 $('#form1').html() 即可
      

  3.   

    natineprince   为什么啊????感谢XF,,,
      

  4.   


    #form1 *取的是#form1下的所有元素,html()取得第一个匹配元素的html内容,也就是到p中的HTML