我想:
yes
或no
no
,则显示提示甜蜜sweetAlert("Oops...", "Something went wrong!", "error");
,如果yes
显示提醒swal("Good job!", "You clicked the button!", "success")
我的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>alert sweet send form</title>
<script src="sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="sweetalert.css">
</head>
<body>
<input type="text" id="username" required placeholder="userName">
<br>
<br>
<input type="text" id="password" required placeholder="passWord">
<br>
<br>
<button onclick="validation();">Đăng nhập</button>
<script src="sweetalert.min.js"></script>
<script type="text/javascript">
function validation() {
var userName = document.getElementById('username').value;
var passWord = document.getElementById('password').value;
if ((username == userName) && (password == passWord)) {
swal({
title: "Bạn Đăng Nhập Thành Công!",
timer: 4000,
showConfirmButton: false
});
} else {
sweetAlert("Lỗi...", "Mật khẩu hoặc tài khoản không đúng!", "error");
}
}
</script>
</body>
</html>
答案 0 :(得分:0)
你的功能必须像这样
function validation()
{
var userName = document.getElementById('username').value;
var passWord = document.getElementById('password').value;
swal({
title: "Are you sure?",
text: "your message",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
swal("Good job!!", "You clicked the button!", "success");
// place your code here
} else {
swal("Oops...", "Something went wrong!", "error");
}
});
}
答案 1 :(得分:0)
<?php
//ket nối
include 'database.php';
//Hiển thị
if(isset($_POST['save'])){
$id= $_POST['id'];
$username= $_POST['username'];
$password= $_POST['password'];
$sql="insert into `members`(id,username,password) Values ('$id','$username','$password')";
// mysql_query("SET NAMES 'UTF8'");
$pdo->exec($sql);
//echo '<script type="text/javascript">alert("Xin chúc mừng, tài khoản được tạo thành công !");window.location ="http://localhost/"; </script>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>alert sweet send form</title>
<script src="sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="sweetalert.css">
</head>
<body>
<form action="index.php" method="post">
<input type="text" id="username" name="username" required placeholder="userName">
<br>
<br>
<input type="text" id="password" name="password" required placeholder="passWord">
<br>
<br>
<button onclick="validation();" name="save">Đăng nhập</button>
</form>
<script src="sweetalert.min.js"></script>
<script type="text/javascript">
function validation()
{
var userName = document.getElementById('username').value;
var passWord = document.getElementById('password').value;
swal({
title: "Are you sure?",
text: "your message",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
swal("Good job!!", "You clicked the button!", "success");
// place your code here
} else {
swal("Oops...", "Something went wrong!", "error");
}
});
}
</script>
</body>
</html>