跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 如何在数组内一个元素引用另一个元素?
未分類
18 1 月 2021

如何在数组内一个元素引用另一个元素?

如何在数组内一个元素引用另一个元素?

資深大佬 : soooulp 6

我想将每个图标打开的次数分别存储在油猴里面,建了一个数组分别存放图标的名称、图片、链接、弹出的信息,弹出的信息是一个函数,点击图标时执行打开链接和统计次数

我需要在函数里面引用当前的图标的名称,如何通过 JavaScript 实现呢?或者是否有其他的办法?

在这个脚本基础上改的 https://greasyfork.org/zh-CN/scripts/404859

 var iconArray = [         {             name: 'Google',             image: 'https://i.ibb.co/R9HMTyR/1-5.png',             host: ['www.google.com'],             popup: function (text, name) {                 open('https://www.google.com/s?wd=' + encodeURIComponent(text), name);                 console.log(name);             }         },         {             name: 'Bing',             image: 'https://i.ibb.co/R9HMTyR/1-5.png',             host: ['www.bing.com'],             popup: function (text, name) {                 open('https://www.bing.com/s?wd=' + encodeURIComponent(text), name);                 console.log(name);             }         },     ] 
function open(url, a) {          try {              if(GM_openInTab(url, { loadInBackground: true, insert: true, setParent :true })){                      if(GM_getValue(a).times){                         GM_setValue(a, {                             'times': GM_getValue(a).times + 1                         });                     }else{                         GM_setValue(a, {                             'times': 1                         });                     }                     console.log('times-'+GM_getValue(a).times);               } else{               }          } catch (error) {              return GM_openInTab(url, { loadInBackground: true, insert: true, setParent :true });          }     } 

我想在油猴里面这样存放数据,打开 Google 1 次,Bing 4 次

{     "Google": {         "times": "1",     },     "Bing": {         "times": "4",     },        } 

大佬有話說 (1)

  • 資深大佬 : AndyAO

    前几天我想在 Json 中这么做
    但搜索之后发现是不行的
    如果非要这么做的话,可以先定规则,再解析

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具