javascript – 警报未出现在chrome扩展程序的popup.html中

前端之家收集整理的这篇文章主要介绍了javascript – 警报未出现在chrome扩展程序的popup.html中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我还是很新的chrome扩展,我只是测试一下.
现在我有一个popup.html,它有一个简短的表单,我想在点击提交时创建一个提醒.我不能为我的生活弄清楚为什么它不起作用.
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Test</title>
  5. <script type="text/javascript" src="popup.js">
  6.  
  7. </script>
  8. </head>
  9. <body onload="alert('open')">
  10. <form>
  11. Username: <input type='text' id="username" name='username'></input>
  12. Password: <input type='password' id='password' />
  13. <button onclick="alert('test');return false;">Login</button>
  14. </form>
  15. </body>
  16. </html>

有什么建议?

编辑:我甚至在body标签中进行了一次onload,看看是否会在那里打开警报但是没有.在popup.js中,我在window.onload上打开了一个警报,但是它有效.

解决方法

返回false后,该函数停止.
在语句结束时返回false,然后您的警报应该有效.或者你可以把它拿出来.
  1. <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. ).

Source here

猜你在找的JavaScript相关文章