jQuery plugin 开发的一个例子
生活随笔
收集整理的這篇文章主要介紹了
jQuery plugin 开发的一个例子
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
測試代碼:
<html> <script src="jquery_1.7.1.js"> </script> <script>jQuery.fn.println = function() {var msg = Array.prototype.join.call(arguments, " ");this.each(function(){ jQuery(this).append(document.createTextNode(msg)).append("<br/>");});return this;};jQuery.debug = function() {var elt = jQuery("#debug");if( elt.length == 0) {elt = jQuery("<div id = 'debug'><h1>Debugging output </h1></div>");jQuery(document.body).append(elt);}elt.println.apply(elt,arguments);}; function start() {var x = "hello world";var y = 23;jQuery.debug("x = ", x , " y = ", y); } </script> <body id = "main" οnlοad="start();"> <h1 id = "header">hello</h1> </body> </html>在$的prototype上增加一個(gè)println的方法:
使用代碼創(chuàng)建一個(gè)新的text node用于輸出debug 內(nèi)容:
調(diào)用prototype上定義的println方法:
輸出debug 內(nèi)容:
最后結(jié)果:
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的jQuery plugin 开发的一个例子的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML里Dom onload和jQue
- 下一篇: SAP Fiori Launchpad