自己写了个jquery的例子,但总是说有问题存在内容:
<!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 ml; charset=gb2312" />
<title>无标题文档</title><style type="text/css">
   .special
   {
   font-weight:bold;
   color:#FF0000;
  }
  $("#ljb").CSS({
  color:#00FF00)};
</style><script type="text/javascript">
function a(){
$("div").addclass("special");
}
  
</script>
</head><body onload="a()"> 
<div id="div1"> aaaa</div>
<div id="sd">
     bbbbbbb
</div>
</body>
</html>
不知道这有什么问题,刚学jquery,各位多给点意见,在自己写的时候就和写script一样吧,没有什么特别的东西吧

解决方案 »

  1.   

    function a(){
    $("div").addClass("special");//注意大小写哦
    }orfunction a(){
    $("div").each(function () {
       $(this).addClass("special");//注意大小写哦
    });
    }
      

  2.   

    这样写还是不ok啊,难道还要引用什么jquery的库吗?
      

  3.   

    楼主说对了,貌似你的页面没引入jquery的库啊
      

  4.   

    可以下载jQuery库到你的文件所在路径,或者直接从google和微软的网站上引用
    引用方法:<head>
             <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs
             /jquery/1.4.0/jquery.min.js"></script>
             </head>
    或者:<head>
         <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery
         /jquery-1.4.min.js"></script>
         </head>
      

  5.   

    jquery库csdn就有下的,就是一个js文件。用script标签导入即可使用
      

  6.   

    一个js文件有多大,ext也就560k;你想想会多大
    v1.4 160k
    其实你下载一个就知道了~
      

  7.   

    <!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=gb2312" />
    <title>无标题文档</title><style type="text/css">
       .special
       {
       font-weight:bold;
       color:red;
      }
    </style><script type="text/javascript" src="../JQuery/jquery-1.4.2.min.js">
    $().ready(
        function(){
    $("div").addClass("special");
    }
    );
    </script>
    </head><body> <div id="div1"> aaa</div>
    <div >
         bbbb
    </div>
    </body>
    </html>
      

  8.   

    <script language="javascript" type="text/javascript" src="../js/jquery-1.4.2.js"></script>    <%if (false)
          { %>    <script type="text/javascript" src="../js/jquery-1.4.2-vsdoc.js"></script>    <%} %>
      

  9.   


    建议你先看看相关js的基础和jquery的示例、文档、书籍等
    <script type="text/javascript" src="../JQuery/jquery-1.4.2.min.js">
    1、不能在导入js文件的script标签中写代码
    2、$().ready没有这种写法
    $().ready(
      function(){
    $("div").addClass("special");
    }
    );
    </script>修改后
    <script type="text/javascript" src="../JQuery/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
         //ready 函数
         $(document).ready(function () {
              $("div").addClass("special");
         });    //ready简写
         $(function () {
              $("div").addClass("special");
         });
    </script>