javascript - Sweet Alert with form JS (3 input)

标签 javascript html forms css sweetalert

我想在 sweet alert 中实现一个表单。我可以只在里面放一个输入,包括标题和正文。

有一种方法可以自定义警报,文档说,但不允许从我的框架 (customizecss.com) 或我的 style.css 加载类 css3。

我正在尝试通过这种方式在警报中包含一个输入:

swal({
       title: "HTML <small>Title</small>!",
       text: "<input type='text'><label class='my-label'>Name</label>",
       html: true 
});

它不起作用,只显示标签...为什么?

请问有没有什么办法...

谢谢!

甜蜜警报 -> https://github.com/t4t5/sweetalert

最佳答案

你可以使用这个插件来实现你想要的:

https://github.com/taromero/swal-forms

它以语法友好的方式在模式中创建表单:

 swal.withForm({
    title: 'More complex Swal-Forms example',
    text: 'This has different types of inputs',
    showCancelButton: true,
    confirmButtonColor: '#DD6B55',
    confirmButtonText: 'Get form data!',
    closeOnConfirm: true,
    formFields: [
      { id: 'name', placeholder: 'Name Field' },
      { id: 'nickname', placeholder: 'Add a cool nickname' },
      { id: 'password', type: 'password' },

      { name: 'sex', value: 'Male', type: 'radio' },
      { name: 'sex', value: 'Female', type: 'radio' },

      { name: 'skills', value: 'JS', type: 'checkbox' },
      { name: 'skills', value: 'Ruby', type: 'checkbox' },
      { name: 'skills', value: 'Java', type: 'checkbox' },

      { id: 'select',
        type: 'select',
        options: [
          {value: 'test1', text: 'test1'},
          {value: 'test2', text: 'test2'},
          {value: 'test3', text: 'test3'},
          {value: 'test4', text: 'test4'},
          {value: 'test5', text: 'test5'}
        ]}
    ]
  }, function (isConfirm) {
    // do whatever you want with the form data
    console.log(this.swalForm) // { name: 'user name', nickname: 'what the user sends' }
  })

关于javascript - Sweet Alert with form JS (3 input),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30655649/

相关文章:

html - 调整窗口大小时保持复选框在表单中的位置

javascript - 如何配置 Phantom.js?

javascript - 可以在 Grafana 数据源库中导入外部 JavaScript 库

javascript - 我可以使用Javascript搜索HTML5本地存储的部分 key 吗?

html - 仅将 CSS 水平下拉菜单中的顶部索引菜单项居中

javascript - 联系表单中的显示-隐藏警告被延迟

html - 是否有任何客户端工具允许您根据某人的邮政编码在 HTML 表单中自动填充他们的城市和州?

javascript - 显示带有偏移量的时间

javascript - ngFor中加载html时如何调用函数

javascript - HTML - 如何检查文件(.js 或 .css)是否已加载或从缓存中获取?