toggle show

JS 2014. 5. 21. 16:16


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<html>
    <head>
        <title>hello</title>
        <script src='./js/jquery-1.11.1.js'></script>
        <script src='./js/ch15.js'></script>
        <style>
    
        </style>
        <script>
            $(document).ready(function() {
                $('button').click(function(){
                    $('.page').toggle('slow');
                });
                
                                    
            }); //ready
            
            
    
        
        </script>
    </head>
    <body>
        <button>Toggle Show</button>
        <div class='page'>
            <h1>Lorem ipsum dolor sit amet</h1>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
            
        </div>
    </body>
</html>
 


설정

트랙백

댓글

check box

JS 2014. 5. 21. 16:04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
    <head>
        <title>hello</title>
        <script src='./js/jquery-1.11.1.js'></script>
        <script src='./js/ch15.js'></script>
        <style>
    
        </style>
        <script>
            $(document).ready(function() {
                $('#all-check').change(function(){
                        if(this.checked){
                            $('#check-item').children().prop('checked',true);
                        }else{
                            $('#check-item').children().prop('checked',false);
                        }
                });
                    
            }); //ready
            
            
    
        
        </script>
    </head>
    <body>
        <input type='checkbox' id='all-check' />
        <label>All</label>
        <div id='check-item'>
            <input type='checkbox' />
            <label>A option</label>
            <input type='checkbox'/>
            <label>B option</label>
            <input type='checkbox'/>
            <label>C option</label>
        </div>
    </body>
</html>
 


설정

트랙백

댓글

Infinity scroll

JS 2014. 5. 21. 15:17

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html>
    <head>
        <title>hello</title>
        <script src='./js/jquery-1.11.1.js'></script>
        <script src='./js/ch15.js'></script>
        <style>
    
        </style>
        <script>
            $(document).ready(function() {
                $(window).scroll(function(){
                    var scrollHeight = $(window).scrollTop() + $(window).height();
                    var documentHeight = $(document).height();
                    
                    
                    if(scrollHeight == documentHeight ){
                        $('<h1>Infinity Scroll</h1>').appendTo('body');
                    }
                });    
            }); //ready
            
            
            
            $(document).ready(function() {
            
                
                for(var i =0; i<20; i++){
                    $('<h1>Infinity scroll</h1>').appendTo('body');
                }
            });
            
            
        
        </script>
    </head>
    <body>
 
    </body>
</html>
 


설정

트랙백

댓글

Keyboard event

JS 2014. 5. 21. 14:47

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
    <head>
        <title>hello</title>
        <script src='./js/jquery-1.11.1.js'></script>
        <script src='./js/ch15.js'></script>
        <style>
    
        </style>
        <script>
            $(document).ready(function() {
                $('textarea').keyup(function() {
                    var inputLength = $(this).val().length;
                    var remain = 150 - inputLength;
                    
                    $('h1').html(remain);
                    
                    if(remain >=0){
                        $('h1').css('color','black');
                    }else{
                        $('h1').css('color','red');
                    }
                    
                });
        
 
 
 
            $('input').on({
                    mousedown: function(){
                                     var temp = $('textarea').val();
                                     alert(temp); 
                                }
                });        
            }); //ready
            
        
        </script>
    </head>
    <body>
        <div>
            <p>지금 내 생각을 </p>
            <h1>150</h1>
            <textarea cols='70' rows='5'> </textarea>
            
        </div>
        <input id ='submit' type='button' value="submit" />
    </body>
</html>
 


설정

트랙백

댓글

mouse event 2

JS 2014. 5. 21. 14:37

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
    <head>
        <title>hello</title>
        <script src='./js/jquery-1.11.1.js'></script>
        <script src='./js/ch15.js'></script>
        <style>
    
        </style>
        <script>
            $(document).ready(function() {
                $('textarea').keyup(function() {
                    var inputLength = $(this).val().length;
                    var remain = 150 - inputLength;
                    
                    $('h1').html(remain);
                });
        
        
                // var button = document.getElementById('submit');
//                 
                // button.onclick = function(){
                    // var temp = $('textarea').val();
                    // alert(temp);
                // };
//                 
                $('input').on({
                    mousedown: function(){
                                     var temp = $('textarea').val();
                                     alert(temp); 
                                }
                });        
            }); //ready
            
        
        </script>
    </head>
    <body>
        <div>
            <p>지금 내 생각을 </p>
            <h1>150</h1>
            <textarea cols='70' rows='5'> </textarea>
            
        </div>
        <input id ='submit' type='button' value="submit" />
    </body>
</html>
 


설정

트랙백

댓글