我正在使用 Google 扩展程序从网站表单中收集信息,操纵该信息并根据该信息更改扩展程序的下拉菜单。
<html>
<body>
<h3>Templates</h3>
<select id="dropdownprimary"></select>
<select id="dropdownsecondary">
<option value="BLANK">Choose One</option>
</select>
<script src='ddprimaryLoad.js'></script>
<script src='dropdownprimary.js'></script>
</body>
</html>
单击扩展图标时,“ddprimaryLoad.js”会运行“formvalues.js”,它会从网站表单中收集信息。然后我想在“ddprimaryLoad.js”中使用“formvalues.js”中的变量。目标是根据变量填充下拉列表,但我已将该长代码编辑为警报(长代码也不起作用)。
'ddprimaryLoad.js':
var storage = chrome.storage.local;
chrome.tabs.executeScript({
file: "formValues.js"
});
storage.get(a,function(result){
var b = a;
alert('2nd ' + b); //This will NOT display
});
'formvalues.js':
var storage = chrome.storage.local;
var a = document.getElementById('name').value;
var obj= {};
obj[a] = a;
storage.set(obj);
storage.get(a,function(result){
var b = a;
alert('1st ' + b); //This will display
});
“formvalues.js”中的警报显示,但我无法将信息输入“ddprimaryLoad.js”。我尝试过很多很多不同的方法来执行相同的过程,但这似乎可行。我在这个过程中遗漏了什么还是有更好的方法?我也很乐意绕过“formvalues.js”,但是当......
var c = document.getElementById('name').value;
alert (c);
...放置在“ddprimaryLoad.js”中它也不起作用。