jQuery operasi acara biasa

Operasi acara biasa


tetapan acara peringkat dom1

  • <input type=”text” onclick=”Procedural code” value='tom' />

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

  • itnode.onclick = function(){}

  • itnode.onclick = fungsi;


tetapan acara peringkat dom2

  • itnode.addEventListener(jenis, pemprosesan, aliran acara);

  • itnode.removeEventListener(jenis, Pemprosesan , aliran acara);

  • node.attachEvent();

  • node.detachEvent();


tetapan acara jquery

  • $ ( ).Jenis acara (fungsi pemprosesan acara fn); //Tetapkan acara

  • $().Jenis acara(); //Pencetuskan pelaksanaan acara

  • Jenis acara: klik, keyup, keydown, mouseover, mouse out, blur, focus, dll.

  • Contohnya: $('div').click(function(){ proses Pencetus peristiwa ini});

Nota: Kaedah di dalam fungsi acara ini mewakili objek nod dom di dalam objek jquery.

<!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>
Meneruskan pembelajaran
||
<!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>
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!