按下按钮确认的JavaScript警告框 [英] JavaScript alert box with confirm on button press

查看:127
本文介绍了按下按钮确认的JavaScript警告框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个链接:

< p id =accept-favor>< a title =接受此赞成href =?wp_accept_favor =<?php comment_ID();?>>接受此赞成< / a>< / p>

当用户点击它时,我想显示一个JavaScript警告框:您确定要接受此回复作为您的帮助吗?使用两个按钮,一个说是,这将允许该功能运行,另一个说否,它将取消回发并使用户保持在页面上。

I want to show a JavaScript alert box when a user clicks it saying: "Are you sure you would like to accept this reply as your favor?" with two buttons one saying "Yes" which will allow the function to run and the other saying "No" which will just cancel the postback and keep the user on the page.

我怎么做?谢谢:)

推荐答案

您可以通过确认onclick轻松完成:

You can easily do it with a confirm onclick:

<p id="accept-favor"><a title="Accept this Favor" 
  href="?wp_accept_favor=<?php comment_ID(); ?>" 
  onclick="return confirm('Are you sure you would like to accept this reply as your favor?');"
  >Accept this Favor</a></p>

虽然这会说OK / Cancel而不是Yes / No。如果你真的想要是/否,你将不得不使用自定义对话框。

Though this will say OK/Cancel instead of Yes/No. If you really want Yes/No, you'll have to use a custom dialog.

这篇关于按下按钮确认的JavaScript警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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