Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在更改后的selectbox上运行chrome.cookies.set_Javascript_Html_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript 在更改后的selectbox上运行chrome.cookies.set

Javascript 在更改后的selectbox上运行chrome.cookies.set,javascript,html,google-chrome,google-chrome-extension,Javascript,Html,Google Chrome,Google Chrome Extension,我在这件小事上遇到了不少麻烦,我希望有人能帮我 <select id="routeBox" name="routeBox" onchange="javascript: getRoute(route, routeBox.selectedIndex); setCookies('http://127.0.0.1/*', 'routeCookie', routeBox.options.selectedIndex);"> </select> 该功

我在这件小事上遇到了不少麻烦,我希望有人能帮我

    <select id="routeBox" name="routeBox" 
    onchange="javascript: getRoute(route, routeBox.selectedIndex);
    setCookies('http://127.0.0.1/*', 'routeCookie', routeBox.options.selectedIndex);">
    </select>
该功能位于脚本标记中的selectBox上方

任何帮助都会很好

谢谢

几件事:

除非route是一个全局变量,否则它当前在onchange范围内未定义。 我会用这个关键字引用routeBox对象。 您不需要将javascript:text添加到onchange属性中。 这是您的代码,已修改:

<select id="routeBox" name="routeBox" 
        onchange="getRoute(route, this.selectedIndex);
        setCookies('http://127.0.0.1/*', 'routeCookie', this.selectedIndex);">
</select>

您的代码看起来很好,API看起来也很正确,所以我只能想象您可能忘记在清单中声明了。

这次不是Serg:It’s my background.html。这些函数单独工作,但我无法让它在OnChange中运行。路由定义在哪里?它正在传递给getRoute。route在我的正文脚本中的selectBox下面定义。既然你提到了它,我不太清楚它是如何工作的。你有没有试过在setCookies函数中调用chrome.cookies API之前放置一个alert或console.log?这可能有助于我们确定是否正在调用该函数。@Alasdair我在chrome.cookies.set之后有一个警报。但是我在chrome.cookies.set之前将警报移到了fire,它给了我一个警报!所以现在我知道它正在调用那个函数,但现在我不知道为什么它不再工作了。谢谢你对关键字的建议。我确实需要selectedIndex而不是值,但问题是setCookies似乎不会在更改selectBox后运行。到目前为止,评论不错,谢谢!没有错误。我在函数中放置了警报,它们会运行,但chrome.cookies.set似乎没有任何作用。我已经在浏览器选项中检查了我的cookies,看看它是否设置了。不幸的是,事实并非如此。除非我的cookies声明中没有正确的地址。权限:[cookies,*],您是否尝试使用*://127.0.0.1作为主机权限?
<select id="routeBox" name="routeBox" 
        onchange="getRoute(route, this.selectedIndex);
        setCookies('http://127.0.0.1/*', 'routeCookie', this.selectedIndex);">
</select>