swal({
title: "Number of Players",
type: "input",
closeOnConfirm: false,
animation: "slide-from-top",
}, function(inputValue){
playersNum = Number(inputValue);
if(inputValue == 1){
swal("Nice!"," ", "success")
} else if(inputValue == 2){
swal("Twice as Nice!"," ", "success");
} else
swal(":(", "Enter a 1 or 2 of Players", "error");
});
$(".confirm:button").click(function() {
alert( "testing" );
});
我有来自http://t4t5.github.io/sweetalert/的这个花哨的代码 这个片段会弹出一个对话框来获取一个数字,该框有一个“确定”按钮可以关闭并继续。单击“确定”后,会弹出另一个框,其中包含一个很酷的复选标记动画,另一个“确定”按钮可以关闭。这些“ok”按钮是动态添加的,具有相同的类。有没有办法让我只使用jQuery或vanilla js定位第二个“ok”按钮?我上面的jQuery针对那个“确定”按钮的两个实例,因此警报弹出两次。
感谢您的帮助。
答案 0 :(得分:0)
根据文档,你可以为按钮添加一个自定义类,就是这种情况,只需在jquery点击功能中定位该类。
答案 1 :(得分:0)
这是Demo
swal({
title: "Number of Players",
type: "input",
closeOnConfirm: false,
animation: "slide-from-top",
}, function(inputValue){
playersNum = Number(inputValue);
if(inputValue == 1)
{
swal("Nice!"," ", "success");
setTimeout(function()
{
$("button.confirm").click(function()
{
alert("this is OK number 2");
// here do what you want when you click on the seconde OK button
});
},250);
} else if(inputValue == 2)
{
swal("Twice as Nice!"," ", "success");
} else
swal(":(", "Enter a 1 or 2 of Players", "error");
});
$(".confirm:button").click(function() {
console.log( "testing" );
});