2015-04-28 762 views
4

我正在使用自定义版本sweetalert向我的用户询问输入。身份证设法使一切正常,但有一个奇怪的行为;为了能够在该输入框中的文字,你必须先点击屏幕:在sweetAlert中输入文本

swal({ 
    title: "Aggiornamento profilo", 
    text: '<br /><form method="post" id="taxcode-update" name="taxcodeUpdate"><input id="admin-tax-code" minlength="3" class="form-control wedding-input-text wizard-input-pad" type="text" name="taxCode" placeholder="Codice fiscale"></form>', 
    type: "warning", 
    showCancelButton: false, 
    confirmButtonText: "Aggiorna il mio profilo", 
    closeOnConfirm: false 
}, function() { 
    swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
}); 

工作例如:https://jsfiddle.net/fvkppx06/

回答

4

JSFiddle

给这个inputautofocus标签。

text: '<br /><form method="post" id="taxcode-update" name="taxcodeUpdate">' 
    + '<input id="admin-tax-code" autofocus minlength="3" class="form-control wedding-input-text wizard-input-pad" type="text" name="taxCode" placeholder="Codice fiscale">' 
    + '</form>', 
+0

该解决方案将只在第一次调用模式,采取这种修改我做证明HTTPS来看一看: //jsfiddle.net/fvkppx06/2/有什么想法? – DomingoSL

+0

我不知道,对不起!尽管[Sweet Alert]的最新版本(http://t4t5.github.io/sweetalert/)允许使用'type:input',这可能会更好? @DomingoSL – Albzi

1

只是测试这个

swal.withForm({ 
    title: 'Cool Swal-Forms example', 
    text: 'Any text that you consider useful for the form', 
    showCancelButton: true, 
    confirmButtonColor: '#DD6B55', 
    confirmButtonText: 'Get form data!', 
    closeOnConfirm: true, 
    formFields: [ 
     { id: 'name', placeholder:'Name Field' }, 
     { id: 'nickname', placeholder:'Add a cool nickname' } 
    ], function(isConfirm) { 
    // do whatever you want with the form data 
    console.log(this.swalForm); // { name: 'user name', nickname: 'what the user sends' } 
}) 

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

8
swal({ 
    title: "An input!", 
    text: "Write something interesting:", 
    type: "input", 
    showCancelButton: true, 
    closeOnConfirm: false, 
    animation: "slide-from-top", 
    inputPlaceholder: "Write something" 
}, 
function(inputValue){ 
    if (inputValue === false) return false; 

    if (inputValue === "") { 
    swal.showInputError("You need to write something!"); 
    return false 
    } 

    swal("Nice!", "You wrote: " + inputValue, "success"); 
}); 
+0

它不工作,第二个参数是意想不到的。你需要现在更新到sweetalert2 –