国产探花免费观看_亚洲丰满少妇自慰呻吟_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) 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 新巴尔虎右旗| 库尔勒市| 淮北市| 安康市| 墨竹工卡县| 铁力市| 原平市| 湘潭市| 张家川| 长治市| 微山县| 东安县| 辽阳县| 芦山县| 石屏县| 博客| 怀仁县| 白山市| 翼城县| 沂南县| 皮山县| 彰化市| 金乡县| 行唐县| 沭阳县| 南宫市| 四子王旗| 淅川县| 无极县| 来安县| 兴山县| 大埔县| 禹州市| 巨野县| 嵊泗县| 龙陵县| 简阳市| 洞头县| 兴宁市| 甘洛县| 兴和县|