问题描述
我不时会遇到一个非常有趣的错误。我的javascript代码在执行期间不显示警报(msg),但如果我使用console.log(msg),它确实会显示在控制台中。什么可以阻止alert()显示?
From time to time, I face a very intriguing bug. My javascript code does not display an alert(msg) during execution, but if I use a console.log(msg) it does show up in the console. What could prevent alert() from displaying?
非常感谢
推荐答案
alert()不起作用的原因是因为之前您已选中阻止此页面创建额外的拨号复选框。
This is a very common problem, and everyone has faced this problem atleast once.The reason alert() does not work is because previously you have checked "prevent this page from creating additional dialoug" checkbox.
让我们来看看这个代码。
lets take a look at this code.
<script type="text/javascript">
var js_name = ['elem1', 'elem2']
for (var i = 0; i < js_name.length; i++) {
alert(js_name[i]);
};
</script>
如果运行代码,将会有两个警告框。如果您选中阻止此页面创建额外的拨号复选框,然后再次刷新页面,您将无法再次获得提示框。
There will be two alert boxes if you run the code. If you check the "prevent this page from creating additional dialoug" checkbox and then refresh the page again you won't get alert box ever again.
您需要解决方案关闭该网页并在浏览器中重新打开(不需要关闭整个浏览器)。
我假设你正在使用chrome。
Internet Explorer或FireFox没有此复选框功能。
Solution is you need to close that webpage and reopen again in the browser(don't need to close the entire browser).I am assuming you are using chrome.Internet Explorer or FireFox doesn't have this checkbox feature.
这篇关于Javascript:为什么有时alert()不起作用但console.log()呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!