简体   繁体   English

如何自定义Javascript Dialogue选项?

[英]How to customize the Javascript Dialogue options?

I am working on an e-commerce website, I want to display a Javascript dialogue box with two options "Go to Cart" & "Continue Shopping", If user clicks on first option control will redirect to Cart page and if user chooses second one it will go to Home page. 我正在开发一个电子商务网站,我想显示一个Javascript对话框,其中有两个选项“转到购物车”和“继续购物”,如果用户点击第一个选项控件将重定向到购物车页面,如果用户选择第二个它将转到主页。

I have an option of using javascript's Confirm() function but I can not change its options to "Add to cart" and "Continue Shopping" 我可以选择使用javascript的Confirm()函数,但我无法将其选项更改为“添加到购物车”和“继续购物”

How can I display such a dialog? 如何显示这样的对话框?

You can not customize confirm dialogue box, but there are several libraries for alerts, 您无法自定义确认对话框,但有几个警报库,

Following are some well known libraries for such purpose 以下是一些众所周知的图书馆

  • Bootbox Bootbox
  • AmaranJS AmaranJS
  • Notie.js Notie.js
  • Sweet Alert 甜蜜警报
  • Alertify.js Alertify.js

The best option to you is to use sweet alert, I'm using it in some projects and it's really easy and looks good. 对你来说最好的选择就是使用甜蜜警报,我在一些项目中使用它,这很容易看起来很好。 Try not to use javascript's confirm... is not very professional 尽量不要使用javascript的确认......不是很专业

https://limonte.github.io/sweetalert2/ https://limonte.github.io/sweetalert2/

you can download it from there and see some examples. 你可以从那里下载并查看一些例子。 For your problem, sweet alert can do something like this: 对于您的问题,甜蜜警报可以做这样的事情:

swal({  title: 'Are you sure?',  text: "You won't be able to revert this!",  type: 'warning',  showCancelButton: true,  confirmButtonColor: '#3085d6',  cancelButtonColor: '#5bc0de',  confirmButtonText: 'Go to cart',  cancelButtonText: 'Continue shopping!',  confirmButtonClass: 'btn btn-success',  cancelButtonClass: 'btn btn-info',  buttonsStyling: false}).then(function () {//redirect to the cart pagewindow.location.assign("/thecartpage.yourextension");}, function (dismiss) {  // dismiss can be 'cancel', 'overlay',  // 'close', and 'timer'... use cancel to this.  if (dismiss === 'cancel') {//Here you close the modal    swal().close();}})

Try Vex plugin for alerts its one of the best UI elements styling and customizing option 尝试Vex插件警报它是最好的UI元素样式和自定义选项之一

http://github.hubspot.com/vex/docs/welcome/ http://github.hubspot.com/vex/docs/welcome/

Try Notie.js Its a clean and simple notification, input, and selection suite for javascript with no dependencies. 尝试Notie.js它是一个简洁的通知,输入和选择套件,适用于没有依赖关系的javascript。

You can get it from here 你可以从这里得到它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM