使用JavaScript创建Chrome式警报 [英] Using JavaScript to create a Chrome-style alert

查看:185
本文介绍了使用JavaScript创建Chrome式警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

img src =https://i.imgur.com/JMAU9o1.jpgalt =漂亮的Chrome提醒>



而不是弹出的提醒一个全新的窗口(在我的Linux Mint GTK主题中):

alert(),那么我会得到一个警报看起来像后者,在一个单独的窗口中。

解决方案

您应该使用对话框元素。就像这样:

HTML:

 < dialog> 
这是一个对话框。< br>
<按钮>关闭< /按钮>
< / dialog>

Javascript:

  var dialog = document.querySelector(dialog)
dialog.querySelector(button)。addEventListener(click,function(){
dialog.close()
$)
dialog.showModal()


How do I create an alert in Chrome using JavaScript that opens a text box in the middle of the browser window and washes out the background, like so:

rather than an alert that just pops up an entirely new window (in my case in the Linux Mint GTK theme):

If I type alert() into the console, I get an alert that looks like the latter, in a separate window.

解决方案

You should use the dialog element. Something like this:

HTML:

<dialog>
  This is a dialog.<br>
  <button>Close</button>
</dialog>

Javascript:

var dialog = document.querySelector("dialog")
dialog.querySelector("button").addEventListener("click", function() {
  dialog.close()
})
dialog.showModal()

这篇关于使用JavaScript创建Chrome式警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆