Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.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
setAttribute函数上的Javascript错误_Javascript_Html - Fatal编程技术网

setAttribute函数上的Javascript错误

setAttribute函数上的Javascript错误,javascript,html,Javascript,Html,我得到这个错误。代码似乎很好,然后我在使用JSFIDLE,但在我的页面中无法获取错误: TypeError:无法读取null的属性“setAttribute”。 max=2160; 让进步=80; document.querySelector(“.fill”).setAttribute( “风格”, “行程偏移量:”+((100-进度)/100)*最大值) 按类查询选择器返回数组类型,尝试将[id]添加到html代码中,然后使用它,这样它告诉您document.querySelector(“

我得到这个错误。代码似乎很好,然后我在使用JSFIDLE,但在我的页面中无法获取错误:

TypeError:无法读取null的属性“setAttribute”。

max=2160;
让进步=80;
document.querySelector(“.fill”).setAttribute(
“风格”,
“行程偏移量:”+((100-进度)/100)*最大值)


按类查询选择器返回数组类型,尝试将[id]添加到html代码中,然后使用它

,这样它告诉您
document.querySelector(“.fill”)
null
。你检查过你的HTML了吗?这个类中有元素吗?@El_Vanja用HTML更新了帖子脚本在哪里?您是否确保它在页面加载后立即运行?El_Vanja我正在使用laravel。代码包含在另一个刀片中(不在主页中)@El_Vanja oh u让我走上了真实的道路!:)对不起,英语不好。我把代码放在最后,开始工作!谢谢不对
querySelector
返回第一个匹配的DOM元素<另一方面,code>querySelectorAll
返回一个元素数组。