Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以从 json 文件执行脚本吗?例如:
helloworld.json { "script" : "console.log('helloworld');" }
我想在我的 html 或 js 文件中的 json 文件中运行脚本。
将 eval 指向字符串以将其作为代码执行
var json = {"script":"console.log('helloworld');"} eval(json["script"])
另请参阅执行存储为字符串的 JavaScript 代码
是的,你必须:
eval()
这是否是一个好主意取决于您的具体用例。