对用户使用 js 警报是否会令人皱眉

发布于 2024-10-16 08:07:31 字数 274 浏览 4 评论 0原文

我的用户正在填写一个小表格(只是电子邮件地址),我通过 JavaScript 将此数据发送到服务器。我发送表单,然后清除字段中的数据。

简单地向用户提供一个像 alert('Your email has shown') 这样的 js 警报,而不是添加标记来显示消息,这是一种不好的做法吗?我今天不经常看到它,所以我想知道它是否反映了一些认为使用警报不好的看法。不过,它使代码变得更容易,我想知道为什么不呢!

还有一个附带问题,是否可以仅设计此警报的样式,使其看起来不那么糟糕?

My user is filling out a small form (just the email address) and I send this data to the server via javascript. I send the form, then clear the data from the fields.

Is it bad practice to simply give the user a js alert like alert('Your email has been added') as opposed to adding markup to display the message? I don't see it often today, so I'm wondering if it reflects some perception that using alerts isn't good. It makes the code much easier though, and I wonder why not!

And a side question, is it possible to just style this alert so it doesn't look so bad?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

沧桑㈠ 2024-10-23 08:07:31

alert 会打断用户正在做的任何事情。这不好,只有在绝对必要的情况下才应该这样做。警报不是必需的,因为用户无论如何都只有一种继续的方式。

alert interrupts the user in whatever he was doing. That's not good and should only be done if it is absolutely necessary. An alert is not necessary, because the user has only one way to continue anyway.

情深已缘浅 2024-10-23 08:07:31

当弹出警报不断出现时,这不是一个非常愉快的用户体验。很烦人,因为它们打断了你正在做的事情,你必须点击一个按钮才能继续你正在做的事情。过度使用会使它们不太可能被阅读,当出现真正重要的事情或用户必须做出选择时,会导致大问题。

在界面中拥有更复杂的反馈可以创造更好的体验。

It's not a very pleasant user experience when popup alerts keep appearing. Annoying as they interrupt what you are doing and you have to click on a button to carry on what you are doing. Excessive use makes it very unlikely that they will ever be read, causing big problems when something actually important comes up or the user has to make a choice.

Having more sophisticated feedback in the interface creates a much better experience.

﹏半生如梦愿梦如真 2024-10-23 08:07:31

既然你用 jquery 标记了它,

$('#my-form').prepend('<p class="notice">Your email has been added</p>');

那真的那么难吗?

Since you tagged this with jquery

$('#my-form').prepend('<p class="notice">Your email has been added</p>');

Was that really so hard?

像你 2024-10-23 08:07:31

如果您页面的主要目的是收集电子邮件地址,我认为使用警报框是完全有效的。

我认为您不再看到这种做法的主要原因是您设置警报框样式的可能性有限。

即它不是很Web 2.0

If the main purpose of your page is to collect the email address I think it is perfectly valid to use an alert box.

I think the main reason you don't see this practise any longer, is that you have limited possibility to style the alert box.

I.e. it is not very Web 2.0

山色无中 2024-10-23 08:07:31

“还有一个附带问题,是否可以仅设计此警报的样式,使其看起来不那么糟糕?”
没有。而且您无法更改标题、设计或类似内容,它纯粹取决于浏览器!

我个人觉得当左右和中间弹出警报时很烦人,它们是模态的,所以你必须点击它们,虽然它们在过去被大量使用,但如今,写一些东西通常更容易被接受进入网页。与警报对话框相比,它有许多优点:

  • 您可以根据自己的需要设置皮肤
  • 它不会让用户烦恼
  • 有时现在的浏览器可以完全阻止网站显示警报对话框(因为它们太烦人了)
  • 单击“确定”后,警报对话框就会消失,您必须记住它在抱怨什么或说了什么。如果它内置于页面中,那么此信息将保留在那里供您查看。

如果您现在确实需要一个类似模态的对话框(对于这种情况,我想说您不需要),那么使用 JS 库来模拟对话框更为常见。这样您就可以获得所需的确切行为,它可以看起来与网页保持一致,并且不能被浏览器关闭。

"And a side question, is it possible to just style this alert so it doesn't look so bad?"
Nope. And you can't change the title, design or anything like that, it's purely browser dependant!

I for one find it annoying when alerts pop up left right and centre, they're modal so you HAVE to click on them and while they were used a lot for that back in the day, these days it's generally much more accepted to write something into the web page. This has a number of advantages over an alert dialog:

  • You can skin it to suit your needs entirely
  • It doesn't annoy the user as much
  • Sometimes browsers these days can prevent sites from displaying alert dialogs at all (because they're so annoying)
  • An alert dialog disappears as soon as you click OK, you have to remember what it was moaning about or what it said. If it's built into the page then this information remains there for you to see.

If you genuinely need a modal-like dialog box these days (and for this case I'd say you didn't) it's far more common to use a JS library to emulate one. That way you can get the exact behaviour you want, it can look in keeping with the web page and can't be turned off by the browser.

听闻余生 2024-10-23 08:07:31

如今,就 UI 设计而言,alert() 在很大程度上被视为一种不优雅的解决方案。考虑到这一点,这实际上取决于环境 - 如果它是一个面向公众的消费者网站,我会尽可能避免使用alert(),因为它会扰乱用户的流程。如果它是一个后端风格的公司网站,管它呢,警报在那里可以正常工作(但仍然要使用你的判断,轻量级标记永远不会伤害任何人)。

alert() is largely seen as a non-graceful solution in terms of UI design these days. With that in mind, it really comes down to the environment - if it's a public facing consumer website, I avoid using alert() whenever possible as it disrupts the user's flow. If it's a backend-style corporate website, screw it, an alert can work fine there (but still use your judgement, lightweight markup never hurt anyone).

丶视觉 2024-10-23 08:07:31

它们很烦人,破坏流程,我个人认为它们只适合“提醒”用户某些事情。比如一条消息,通知您您已经注册,这更像是“确认”。在 Web 2.0 时代,人们期望这些东西以更永久的形式出现在主网页/GUI 上。

They're annoying, break the flow and personally I think they're only appropriate for 'alerting' users to something. Something like a message to inform you that you've been registered which is more 'confirmation. and the expectation in these Web 2.0 days is that such things appear in a more permanent form on the main webpage/ GUI.

清欢 2024-10-23 08:07:31

在我看来,它相当引人注目,因为它模糊了无害的网络错误消息(例如,您忘记输入密码!)和更严重的应用程序错误之间的区别。

另外,如果处理不当,就不可能连续出现 3-4 个错误,这非常烦人。

然而,它实现起来既简单又快捷,可以引起用户的注意,并保证他们在看到错误消息并按下“确定”之前无法执行任何操作。

至于造型,你不能。但是看看 jGrowl,它有一个非常好的处理错误消息的方法。

In my opinion it's quite obtrusive as it blurs the difference between harmless web error messages (for example, you forgot to enter your password!) and more serious application errors.

Also if you don't handle them properly, you can't get 3-4 consecutive errors which is extremely annoying.

It's easy and quick to implement however, gets the user attention, and guarantees they won't be able to do anything until they have seen and pressed ok on the error message.

As for styling, you can't. But take a look at jGrowl, it has a really nice way of doing error messages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文