国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jQuery中$this和$(this)的區別介紹(一看就懂)

2024-05-06 16:22:45
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了jQuery中$this和$(this)的區別介紹(一看就懂),本文用簡潔的語言講解了它們之間的區別,并給出了一個例子來說明,需要的朋友可以參考下

  1. // this其實是一個Html 元素。 
  2. // $this 只是個變量名,加$是為說明其是個jquery對象。 
  3. // 而$(this)是個轉換,將this表示的dom對象轉為jquery對象,這樣就可以使用jquery提供的方法操作。 
  4.  
  5.  
  6. (function($){ 
  7. $.fn.hilight = function(options){ 
  8. debug(this); 
  9.  
  10. var defaults = { 
  11. foreground: 'red'
  12. background: 'yellow' 
  13. }; 
  14.  
  15. var opts = $.extend({}, $.fn.hilight.defaults, options); 
  16.  
  17. return this.each(function() { 
  18. // this其實是一個Html 元素。 
  19. // $this 只是個變量名,加$是為說明其是個jquery對象。 
  20. // 而$(this)是個轉換,將this表示的dom對象轉為jquery對象,這樣就可以使用jquery提供的方法操作。 
  21. $this = $(this); 
  22.  
  23. // build element specific options 
  24. var o = $.meta ? $.extend({}, opts, $this.data()) : opts; 
  25.  
  26. // update element styles 
  27. $this.css({ 
  28. backgroundColor: o.background, 
  29. color: o.foreground 
  30. }); 
  31.  
  32. var markup = $this.html(); 
  33. // call our format function 
  34.  
  35. markup = $.fn.hilight.format(markup); 
  36.  
  37. $this.html(markup); 
  38. }); 
  39.  
  40. }; 
  41.  
  42.  
  43. // define our format function 
  44. $.fn.hilight.format = function(txt) { 
  45. return '<strong>' + txt + '</strong>'
  46. }; 
  47.  
  48.  
  49. // 插件的defaults 
  50. $.fn.hilight.defaults = { 
  51. foreground: 'red'
  52. background: 'yellow' 
  53. }; 
  54.  
  55. function debug($obj) { 
  56. if (window.console && window.console.log){ 
  57. window.console.log('hilight selection count: ' + $obj.size()); 
  58. }; 
  59.  
  60. })(jQuery) 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 和平区| 饶河县| 平南县| 禹城市| 阿合奇县| 桐乡市| 甘洛县| 佛学| 三原县| 甘南县| 依安县| 和平县| 宁阳县| 长海县| 清水河县| 古交市| 邳州市| 韩城市| 赫章县| 达日县| 芦山县| 北票市| 哈巴河县| 砀山县| 宜春市| 延长县| 肇庆市| 博乐市| 南雄市| 剑河县| 酒泉市| 临夏县| 新野县| 汝城县| 佳木斯市| 蛟河市| 贡觉县| 宁国市| 麟游县| 叶城县| 洪洞县|