jQuery 锚标签中的jquery确认功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18078446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 20:58:30  来源:igfitidea点击:

Jquery Confirm function in anchor tag

javascriptjquery

提问by user

Normally when click anchor tag it redirects to some url which is given inside the "href" attribute. Is there is any possiblity here for confirmation. When we click anchor tag it shows confirmation "Are you sure want to continue" if we clicked "yes" it gets redirect to that url which is given inside "href". if we click "no" it remains in same page. Please share any ideas you might have.

通常,当单击锚标记时,它会重定向到“href”属性中给出的某个 url。这里是否有任何可能性进行确认。当我们单击锚标记时,它会显示确认“您确定要继续吗”,如果我们单击“是”,它会重定向到“href”中给出的那个 url。如果我们单击“否”,它会保留在同一页面中。请分享您可能有的任何想法。

回答by Satpal

Try this

尝试这个

<a href="http://www.google.com" onclick="return confirm('Are you sure?')" >click here</a>

回答by putvande

You could do something like:

你可以这样做:

$('a').click(function(){
    return confirm('Are you sure want to continue?');
});

Therefore if the user click's cancel you return falseand the link won't send you anywhere.

因此,如果用户点击取消,您将返回false并且链接不会将您发送到任何地方。

回答by Laeeq

You can do this by using below html link and jquery code. Don't forget to include Jquery library from http://jquery.com.

您可以通过使用下面的 html 链接和 jquery 代码来做到这一点。不要忘记包含来自http://jquery.com 的Jquery 库。

<a href="go.html?id=22" class="confirm">Go>></a>

<!-- Include jQuery - see http://jquery.com -->
<script type="text/javascript">
    $('.confirm').on('click', function () {
        return confirm('Are you sure want to continue?');
    });
</script>

回答by Arun P Johny

Yes

是的

$('a').click(function(){
    return confirm('do you want to proceed')
})

回答by Khadim Ali

Try

尝试

<a href="www.anysite.com" onclick="return confirm('Are you sure?')">Any site</a>

回答by Samuel

$('a').click(function(){return confirm('sure?')})

回答by Aviv Shaked

If you want a stylish box, jQuery has a Dialog Widget. This is the link to the widget's API: Dialog Widget - Open content in an interactive overlay.

如果你想要一个时尚的盒子,jQuery 有一个 Dialog Widget。这是小部件 API 的链接: 对话框小部件 - 在交互式叠加中打开内容。

I would use it as part of my confirm().

我会将它用作我的确认()的一部分。