본문 바로가기

jQuery

jQuery 5

collapsible.list.take.1.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Collapsible List &mdash; Take 1</title>
    <link rel="stylesheet" type="text/css" href="../common.css">
    <script type="text/javascript"
            src="../scripts/jquery-1.2.1.js"></script>
    <script type="text/javascript">
      $(function(){
        $('li:has(ul)')
          .click(function(event){
            if (this == event.target) {
              if ($(this).children().is(':hidden')) {
                $(this)
                  .css('list-style-image','url(minus.gif)')
                  .children().show();
              }
              else {
                $(this)
                  .css('list-style-image','url(plus.gif)')
                  .children().hide();
              }
            }
            return false;
          })
          .css('cursor','pointer')
          .click();
        $('li:not(:has(ul))').css({
          cursor: 'default',
          'list-style-image':'none'
        });
      });
    </script>
    <style>
      fieldset { width: 320px }
    </style>
  </head>

  <body>
    <fieldset>
      <legend>Collapsible List &mdash; Take 1</legend>
      <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>
          Item 3
          <ul>
            <li>Item 3.1</li>
            <li>
              Item 3.2
              <ul>
                <li>Item 3.2.1</li>
                <li>Item 3.2.2</li>
                <li>Item 3.2.3</li>
              </ul>
            </li>
            <li>Item 3.3</li>
          </ul>
        </li>
        <li>
          Item 4
          <ul>
            <li>Item 4.1</li>
            <li>
              Item 4.2
              <ul>
                <li>Item 4.2.1</li>
                <li>Item 4.2.2</li>
              </ul>
            </li>
          </ul>
        </li>
        <li>Item 5</li>
      </ul>
    </fieldset>
  </body>
</html>

===========================================
collapsible.list.take.2.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Collapsible List &mdash; Take 2</title>
    <link rel="stylesheet" type="text/css" href="../common.css">
    <script type="text/javascript"
            src="../scripts/jquery-1.2.1.js"></script>
    <script type="text/javascript">
      $(function(){
        $('li:has(ul)')
          .click(function(event){
            if (this == event.target) {
              $(this).children().toggle();
              $(this).css('list-style-image',
                ($(this).children().is(':hidden')) ?
                  'url(plus.gif)' : 'url(minus.gif)');
            }
            return false;
          })
          .css('cursor','pointer')
          .click();
        $('li:not(:has(ul))').css({
          cursor: 'default',
          'list-style-image':'none'
        });
      });
    </script>
    <style>
      fieldset { width: 320px }
    </style>
  </head>

  <body>
    <fieldset>
      <legend>Collapsible List &mdash; Take 2</legend>
      <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>
          Item 3
          <ul>
            <li>Item 3.1</li>
            <li>
              Item 3.2
              <ul>
                <li>Item 3.2.1</li>
                <li>Item 3.2.2</li>
                <li>Item 3.2.3</li>
              </ul>
            </li>
            <li>Item 3.3</li>
          </ul>
        </li>
        <li>
          Item 4
          <ul>
            <li>Item 4.1</li>
            <li>
              Item 4.2
              <ul>
                <li>Item 4.2.1</li>
                <li>Item 4.2.2</li>
              </ul>
            </li>
          </ul>
        </li>
        <li>Item 5</li>
      </ul>
    </fieldset>
  </body>
</html>

===========================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
 
  <script>
   $(document).ready(function(){
     $(document.body).click(function () {
    $(document.body).append($("<div>"));
    var n = $("div").size();
    $("span").text("There are " + n + " divs." + "Click to add more.");
    }).click(); // trigger the click to start
   });
  </script>
  <style>
  body { cursor:pointer; }
   div { width:50px; height:30px; margin:5px; float:left; background:blue; }
   span { color:red; }
 </style>
</head>
<body>
  <span></span>
</body>
</html>

'jQuery' 카테고리의 다른 글

객체지향 자바스크립트 2-1  (0) 2009.12.14
jQuery 유용한 사이트 (퍼옴)  (0) 2009.09.26
jQuery 4-2  (0) 2009.09.26
jQuery 4  (0) 2009.09.26
DOM 이해하기(퍼옴)  (0) 2009.09.25