JavaScript DHTML/jQuery/extend

Материал из Web эксперт
Перейти к: навигация, поиск

extends array

   <source lang="html4strict">
  

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">
       $(document).ready(function(){
             var a = { a: "A", c: 5, b: "B" };
             var b = { a: "AA", b: "BB" };
             jQuery.extend(a, b);
            
             
       });
   </script>
 </head>
 <body>
   <body>

   </body>

</html>


 </source>
   
  


Extend select, unselect

   <source lang="html4strict">

<html>

 <head>
   <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
   <script type="text/javascript">

$.fn.extend({

 Select: function() {
   return $(this).addClass("mySelected");
 },
 Unselect: function() {
   return $(this).removeClass("mySelected");
 },
 MyApplication: {
   Ready: function() {
     $("p").click(
       function($e) {
         $("li").Select();
       }
     );
     $("li").click(
       function() {
         $(this).hasClass("mySelected")?$(this).Unselect() : $(this).Select();   
       }
     );
   }
 }

}); $(document).ready(

 function() {
   $.fn.MyApplication.Ready();
 }

);

   </script>
   <style type="text/css">

li.mySelected {

   background: yellow;

}

   </style>
 </head>
 <body>
  • A
  • B
  • C
  • D
  • E
  • F

Select All

 </body>

</html>

 </source>