Javascript 如何在Swal SWEETEALERT中仅允许数字
我想知道我怎么能在这部分只允许数字Javascript 如何在Swal SWEETEALERT中仅允许数字,javascript,html,node.js,bootstrap-4,sweetalert,Javascript,Html,Node.js,Bootstrap 4,Sweetalert,我想知道我怎么能在这部分只允许数字 { title: "Dollar Amount?", text: "How much is your Dollar Question worth?", inputPlaceholder: "Enter Amount" } 我正在使用Sweetalert插件。这已经困扰了我好几天了,我只是一个新的前端,我真的是一个完整的后端家伙 function showDollarQuestion() { if (inUserId ===
{
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()
})
}
}
函数showDollarQuestion(){
if(inUserId==“”| | inUserId===null){
emit('studnotif',myuserid,myuserid,“noroom”);
}否则{
swal.setDefaults({
输入:“文本”,
confirmButtonText:“下一个&rarr;”,
showCancelButton:true,
动画:错,
进度步骤:['1','2']
})
变量步骤=[
{
标题:“美元问题?”,
文字:“向你的影响者提问”,
输入占位符:“写下你的美元问题”
},
{
标题:“美元金额?”,
文本:“你的美元问题值多少钱?”,
输入占位符:“输入金额”
}
]
swal.queue(步骤).then(函数(结果){
如果(结果[1]==“”| |结果[1]==“”){
swal.resetDefaults()
游泳({
标题:“空字段!”,
html:
“需要美元问题
需要美元金额”,
confirmButtonText:“重试”,
showCancelButton:false
})
}else if(){
}否则{
swal.resetDefaults()
游泳({
标题:“全部完成!”,
html:
'您的美元问题是'+JSON.stringify(结果[0])。替换(/\“/g,”)+
“
美元问题的价值是”+JSON.stringify(结果[1])。替换(/\“/g”“”),
confirmButtonText:'很好,你的问题已成功提交给你的影响者',
showCancelButton:false
})
emit('dollar quest',JSON.stringify(结果[0])。replace(/\“/g,”),JSON.stringify(结果[1])。replace(/\“/g,”),inUserId,myuserid,'dquest');
}
},函数(){
swal.resetDefaults()
})
}
}
到目前为止,这是我得到的所有代码。我找不到任何关于这件事的教程。提前感谢各位首先,您使用的是SweetAlert2,而不是SweetAlert。这是两个不同的项目,API略有不同 要创建数字字段,应将
输入
参数设置为“数字”
:
Swal.fire({
文字:“你的美元问题值多少钱?”,
输入:“数字”
}).然后(函数(结果){
if(result.value){
const amount=result.value
游泳池火灾(金额+美元)
}
})
但是你可以改变书店,或者你已经习惯了,你可以使用
$('.showSweetAlert').children('fieldset').children('input').attr('type', 'number');
您可以使用“文本”,然后在收到响应时将其格式化为数字(双精度)
“number”不允许使用逗号/点(仅限数字),并将显示警告,直到您将其删除为止hi sir,那么如何使用多个输入?因为在我的原因上,我有一个类似这样的数组,它们都被设置为默认的
input:'text'