Chrome 内容安全政策说,
Inline JavaScript will not be executed. This restriction bans both inline blocks and inline event handlers (e.g.
<button onclick="...">
).
我想用 JS 验证输入。由于不能使用 onsubmit、onclick 或任何东西,我该怎么做?我是 JS 和扩展开发的新手。我们欢迎任何帮助。
最佳答案
您可以使用addEventListener
,例如像这样:
// Function to add event listener to table
var el = document.getElementById("targetElement");
el.addEventListener("click", function() { alert('Hoorey!'); }, false);
这在一个单独的 .js 文件中进行。
关于javascript - 如何使用 JS 为 chrome 扩展程序进行表单验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31446631/