2017-08-02 131 views
1

我想知道我怎麼可以只允許在這部分數字。我怎樣才能讓數字只在斯瓦爾Sweetalert

{ 
    title: "Dollar Amount?", 
    text: "How much is your Dollar Question worth?", 
    inputPlaceholder: "Enter Amount" 
    } 

我正在使用Sweetalert插件。它已經困擾了我好幾天,我只是新的前端,我真的是一個完整的後端人。

function showDollarQuestion() { 

if (inUserId === "" || inUserId === null) { 
    socket.emit('stud notif', myuserid,myuserid,"noroom"); 
}else{ 
    swal.setDefaults({ 
     input: 'text', 
     confirmButtonText: 'Next →', 
     showCancelButton: true, 
     animation: false, 
     progressSteps: ['1', '2'] 
    }) 

    var steps = [ 
     { 
     title: "Dollar Question?", 
     text: "Ask a question to your influencer", 
     inputPlaceholder: "Write your Dollar Question" 
     }, 
     { 
     title: "Dollar Amount?", 
     text: "How much is your Dollar Question worth?", 
     inputPlaceholder: "Enter Amount" 
     } 
    ] 

    swal.queue(steps).then(function (result) { 
     if (result[1] === "" || result[1] === "") { 
      swal.resetDefaults() 
       swal({ 
       title: 'Empty Field!', 
       html: 
        'Dollar Question is required<br />Dollar Amount is required', 
       confirmButtonText: 'Try Again', 
       showCancelButton: false 
      }) 
     }else if(){ 

     }else{ 
      swal.resetDefaults() 
      swal({ 
       title: 'All done!', 
       html: 
        'Your Dollar Question is '+JSON.stringify(result[0]).replace(/\"/g, "")+ 
        '<br /> Dollar Question worth is '+JSON.stringify(result[1]).replace(/\"/g, ""), 
       confirmButtonText: 'Great, your question has been successfully submitted to your influencer', 
       showCancelButton: false 
      }) 
      socket.emit('dollar quest', JSON.stringify(result[0]).replace(/\"/g, ""), JSON.stringify(result[1]).replace(/\"/g, ""), inUserId, myuserid, 'dquest'); 

     } 
    }, function() { 
     swal.resetDefaults() 
    }) 
} 
} 

到目前爲止,這是我得到的所有代碼。我找不到有關Sweetalert的任何教程。在此先感謝球員

回答

0

首先,您正在使用SweetAlert ,而不是SweetAlert。這些是兩個不同的項目,API差別很小。

爲了使數字字段中應該設置input參數'number'

swal({ 
 
    text: 'How much is your Dollar Question worth?', 
 
    input: 'number' 
 
}).then(function(amount) { 
 
    if (amount) { 
 
    swal(amount + ' USD') 
 
    } 
 
})
<link href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.6/sweetalert2.css" rel="stylesheet"/> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.6/sweetalert2.js"></script>

有關input參數的更多詳細信息,請參閱官方文檔頁面:https://sweetalert2.github.io/

+0

喜先生,所以我怎麼能做到多輸入?因爲我的原因我有一個數組類似的東西,他們都設置爲默認爲'''input:'text'''' – TheGinxx009

+0

https://sweetalert2.github.io/#multiple-inputs –