gpt4 book ai didi

javascript - 有没有办法定位屏幕上的按钮?

转载 作者:行者123 更新时间:2023-11-28 06:53:09 25 4
gpt4 key购买 nike

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/ 的奇特代码此代码片段会弹出一个对话框以获取号码,该对话框有一个“确定”按钮用于关闭并继续。单击“确定”后,会弹出另一个框,其中包含很酷的复选标记动画和另一个用于关闭的“确定”按钮。这些“确定”按钮是动态添加的并且具有相同的类。有没有办法让我只使用 jQuery 或 vanilla js 来定位第二个“ok”按钮?我上面的 jQuery 目标是“确定”按钮的两个实例,因此警报会弹出两次。

感谢您的帮助。

最佳答案

这是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" );
});

关于javascript - 有没有办法定位屏幕上的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32792640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com