我对 chrome 扩展还是很陌生,只是在测试。 现在我有一个 popup.html,它有一个简短的表单,我想在单击提交时创建一个警报。我一辈子都弄不明白为什么它不起作用。
<!doctype html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="popup.js">
</script>
</head>
<body onload="alert('open')">
<form>
Username: <input type='text' id="username" name='username'></input>
Password: <input type='password' id='password' />
<button onclick="alert('test');return false;">Login</button>
</form>
</body>
</html>
有什么建议吗?
编辑:我什至在 body 标签中做了一个 onload 以查看警报是否会在那里打开,但它没有。在 popup.js 中,我在 window.onload 上打开了一个警报,但是它有效。
最佳答案
函数在您返回 false 后停止。 将 return false 放在语句的末尾,那么您的警报应该会起作用。或者您可以将其取出。
<button onclick="alert('test')">Login</button>
更新 经过一些研究,我发现了以下...
Inline JavaScript will not be executed
Inline JavaScript, as well as dangerous string-to-JavaScript methods like eval, will not > be executed. This restriction bans both inline blocks and inline event handlers > (e.g. ).
关于javascript - 警报未出现在 chrome 扩展程序的 popup.html 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10064999/