如何保存更改,在$ .change()方法执行后完成 [英] How to save changes, completed after $.change() method executions

查看:157
本文介绍了如何保存更改,在$ .change()方法执行后完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人的好日子!



在开发Chrome扩展程序时,我遇到了以下问题:有一些字段F.它有一个状态指示器。有两种状态选项:绿色和红色(默认)。一旦字段值更新 - 状态指示器应该变为绿色并保持这种状态。



到目前为止,一切都很清楚。我使用

 $ .change()

方法,一切正常。但问题是页面重新加载后,状态指示灯再次变为红色。



问题:如何确保在更改字段后,状态指示灯仍然存在绿色甚至在重新加载页面后?记住结果的一些方法。



我尝试过:



我发现Chrome.storage可以帮助我完成我的问题。但是,我想,我做错了什么。这是我尝试过的,但是这段代码片段不起作用。

 feedViewElement.change(function(){
chrome.storage.onChanged.addListener(function(){
liElement.css(list-style-image,passedStateImgUrl);
aElement.attr(title,passedStateText);
});





我做错了什么?

解决方案

.change()

方法和一切正常。但问题是页面重新加载后,状态指示灯再次变为红色。



问题:如何确保在更改字段后,一旦重新加载页面,状态指示器仍保持绿色?记住结果的一些方法。



我尝试了什么:



我发现Chrome.storage可以在我的问题上帮助我。但是,我想,我做错了。这是我尝试过的,但是这段代码片段没有work。

 feedViewElement.change(function(){
chrome.stora ge.onChanged.addListener(function(){
liElement.css(list-style-image,passedStateImgUrl);
aElement.attr(title,passedStateText);
});





我做错了什么?


在元素上设置存储状态onchange event。



 chrome.storage.sync.set({key:value}, function (){
console .log(' 值设置为' + value);
});



使用下面的代码来获取存储状态并在加载时更新状态。



< pre lang =Javascript> chrome.tabs.onUpdated.addListener( function (tabId,changeInfo,tab){
if (changeInfo.status == ' complete'&& tab。有效){
chrome.storage.sync.get([' key'],< span class =code-keyword> function (result){
console .log( ' 当前值为' + result.key);

if (result.value){
// 设置颜色或图像
}
});


// 做你的事情
}
})


Good day to everyone!

While developing an extension for Chrome, I encountered the following problem: There is some field F. It has a status indicator. There are two status options: green and red (default). As soon as the field value has been updated - the status indicator should turn green and stay that way.

Up to this point, everything is clear. I use the

$.change ()

method and everything works. But the problem is that after the page is reloaded, the status indicator turns red again.

Question: How to ensure that, after changing the field, the status indicator remains green even after reloading of the page? Some way to remember the result.

What I have tried:

I found out that Chrome.storage could help me in my issue. But, I guess, I do something wrong. Here`s what I tried, but this code snippet doesn`t work.

feedViewElement.change(function() {
     chrome.storage.onChanged.addListener(function() {
       liElement.css("list-style-image", passedStateImgUrl);
       aElement.attr("title", passedStateText);
  });



What do I do wrong?

解决方案

.change ()

method and everything works. But the problem is that after the page is reloaded, the status indicator turns red again.

Question: How to ensure that, after changing the field, the status indicator remains green even after reloading of the page? Some way to remember the result.

What I have tried:

I found out that Chrome.storage could help me in my issue. But, I guess, I do something wrong. Here`s what I tried, but this code snippet doesn`t work.

feedViewElement.change(function() {
     chrome.storage.onChanged.addListener(function() {
       liElement.css("list-style-image", passedStateImgUrl);
       aElement.attr("title", passedStateText);
  });



What do I do wrong?


Set status in storage on element onchange event.

chrome.storage.sync.set({key: value}, function() {
         console.log('Value is set to ' + value);
       });


use below code to get stored status and update the status on load.

chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
  if (changeInfo.status == 'complete' && tab.active) {
        chrome.storage.sync.get(['key'], function(result) {
          console.log('Value currently is ' + result.key);

          if(result.value){
           // Set Color or Image
          }
        });


    // do your things
  }
})


这篇关于如何保存更改,在$ .change()方法执行后完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆