简体   繁体   English

Javascript 提示对话框自定义输入

[英]Javascript Prompt dialog customize input

I want to have a field like this in the prompt-dialog in javascript, so the user can quickly select a date我想在 javascript 的提示对话框中有一个这样的字段,以便用户可以快速 select 一个日期

That input field should look like this该输入字段应如下所示

Is there an easy way to do this?是否有捷径可寻?

You can do very customized things with Sweet Alert .您可以使用Sweet Alert做非常定制的事情。

Example with date input:日期输入示例:

const {
  value: formValue
} = await Swal.fire({
  title: 'Select a date',
  html: '<input type="date" id="swal-input" class="swal2-input">',
  focusConfirm: false,
  allowOutsideClick: false,
  preConfirm: () => {
    return document.getElementById('swal-input').value;
  }
})

The result of running this will be a popup in the center of the screen with a date input box:运行此命令的结果将是在屏幕中央弹出一个带有日期输入框的窗口:

在此处输入图像描述

在此处输入图像描述

The selected date will be stored in the variable called formValue .选定的日期将存储在名为formValue的变量中。

Installation instructions安装说明

To get started quickly, you can include this script at the beginning of the HTML:为了快速开始,您可以在 HTML 的开头包含此脚本:

 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>

If I understand your needs I think you can use jQuery datepicker https://jqueryui.com/datepicker/#default如果我了解您的需求,我认为您可以使用 jQuery datepicker https://jqueryui.com/datepicker/#default

if you want the calendar to be inline you can do that too https://jqueryui.com/datepicker/#inline如果您希望日历内联,您也可以这样做https://jqueryui.com/datepicker/#inline

The source code is at the bottom of the pages.源代码位于页面底部。

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

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