jQuery 일반 이벤트 작업

정상적인 이벤트 운영


dom1 레벨 이벤트 설정

  • <input type=”text” onclick=”절차 코드” value='tom' / > ;

  • <input type="text" onclick="function()" />

  • itnode.onclick = function(){}

  • itnode.onclick = function;


dom 레벨 2 이벤트 설정

  • itnode.addEventListener(유형, 처리, 이벤트 흐름);

  • itnode.removeEventListener(유형, 처리, 이벤트 흐름);

  • node.attachEvent();

  • node.detachEvent();


jquery 이벤트 설정

  • $().이벤트 유형(이벤트 처리 함수fn ) / /이벤트 설정

  • $().Event type(); //이벤트 실행 실행

  • 이벤트 유형: 클릭, 키업, 키다운, 마우스오버, 마우스아웃, 흐림, 포커스 등

  • 예를 들어 : $('div').click(function(){이벤트 트리거 프로세스 this});

참고: 이벤트 함수 내의 이 메서드는 jquery 개체 내의 dom 노드 개체를 나타냅니다.

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
        $(function(){
            //页面加载完毕给div绑定事件
            $('div').click(function(){
                console.log('谁在碰我呢');
            });
            //$('li').each(function(){
                //this关键字分别代表每个li的dom对象
                //jquery使用时,代码结构类似这样的,this都代表dom对象
            //});
            $('div').mouseover(function(){
                //this.style.backgroundColor = "blue";
                //$(this)使得this的dom对象变为jquery对象
                $(this).css('background-color','red');
            });
        });
        function f1(){
            //间接触发对象的事件执行
            $('div').click(); //使得div的单击事件执行
            $('div').mouseover();  //鼠标移入事件执行
        }
        </script>
        <style type="text/css">
        div {width:300px; height:200px; background-color:pink;}
        </style>
    </head>
    <body>
        <div></div>
        <input type="button" value="间接操作" onclick="f1()" />
    </body>
</html>
지속적인 학습
||
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(function(){ //页面加载完毕给div绑定事件 $('div').click(function(){ console.log('谁在碰我呢'); }); //$('li').each(function(){ //this关键字分别代表每个li的dom对象 //jquery使用时,代码结构类似这样的,this都代表dom对象 //}); $('div').mouseover(function(){ //this.style.backgroundColor = "blue"; //$(this)使得this的dom对象变为jquery对象 $(this).css('background-color','red'); }); }); function f1(){ //间接触发对象的事件执行 $('div').click(); //使得div的单击事件执行 $('div').mouseover(); //鼠标移入事件执行 } </script> <style type="text/css"> div {width:300px; height:200px; background-color:pink;} </style> </head> <body> <div></div> <input type="button" value="间接操作" onclick="f1()" /> </body> </html>
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!