Ale*_*ora 5 javascript forms html5 css3 sweetalert
我想在甜蜜警报中实现一个表单。我只能在其中输入一个标题和正文。
文档说,有一种自定义警报的方法,但是不允许从我的框架(customizecss.com)或从style.css加载类css3。
我正在尝试通过以下方式在警报中包含输入:
swal({
title: "HTML <small>Title</small>!",
text: "<input type='text'><label class='my-label'>Name</label>",
html: true
});
Run Code Online (Sandbox Code Playgroud)
而且它不起作用,仅显示标签...为什么?
我想知道是否有某种方法可以做到...
谢谢!
小智 4
您可以使用此插件来实现您想要的:
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' }
})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20997 次 |
最近记录: |