jQuery 自定義方法(擴展方法)
阿新 • • 發佈:2017-12-22
opacity () xtend clas eight bsp back hello 定義
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="jquery-3.2.1.js"></script> <style> #div1{ height: 400px; width: 600px background-color: #7b7b7b; opacity: 1; } </style> </head> <body> <div id="div1"></div> <script> (function ($) { $.fn.extend({ hello:function () { setTimeout("$(\"#div1\").css(\"background-color\",\"red\");",2000); setTimeout("$(\"#div1\").css(\"background-color\",\"black\");",4000); setTimeout("$(\"#div1\").css(\"background-color\",\"gold\");",6000); } }) })(jQuery); $("#div1").hello() </script> </body> </html>
jQuery 自定義方法(擴展方法)