登录和密码(Login and Password)
描述 (Description)
您可以使用此类型的模式进行身份验证。 它使用以下方法 -
myApp.modalLogin(text, [title, callbackOk, callbackCancel])
OR
myApp.modalLogin(text, [callbackOk, callbackCancel])
以上方法接受下面列出的参数 -
text - 显示带文本的模态。
title - 这是一个显示带标题的模态的可选方法。
callbackOk - 这是一个可选方法,它提供了当用户单击“确定”按钮时执行的回调函数。
callbackCancel - 这是一个可选方法,它提供了当用户单击“取消”按钮时执行的回调函数。
例子 (Example)
以下示例演示了在Framework7中使用登录名和密码模式,它提供了用于输入用户名和密码以进行身份验证的模式框 -
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, initial-scale = 1,
maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
<meta name = "apple-mobile-web-app-capable" content = "yes" />
<meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
<title>Login and Password Modal</title>
<link rel = "stylesheet"
href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
<link rel = "stylesheet"
href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
</head>
<body>
<div class = "views">
<div class = "view view-main">
<div class = "navbar">
<div class = "navbar-inner">
<div class = "center sliding">Login and Password Modal</div>
</div>
</div>
<div class = "pages">
<div data-page = "index" class = "page navbar-fixed">
<div class = "page-content">
<div class = "content-block">
<p><a href = "#" class = "login-modal">Displays Login Modal</a></p>
<p><a href = "#" class = "password-modal">Displays Password Modal</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
<script type = "text/javascript"
src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>
<script>
// Here you can initialize the app
var myApp = new Framework7();
// If your using custom DOM library, then save it to $$ variable
var $$ = Dom7;
// Add the view
var mainView = myApp.addView('.view-main', {
// enable the dynamic navbar for this view:
dynamicNavbar: true
});
$$('.login-modal').on('click', function () {
myApp.modalLogin('Enter your details:', function (uname, pwd) {
myApp.alert('Username: ' + uname + ', Password: ' + pwd);
});
});
$$('.password-modal').on('click', function () {
myApp.modalPassword('Enter your password:', function (pwd) {
myApp.alert('Your password is: ' + pwd);
});
});
</script>
</body>
</html>
输出 (Output)
让我们执行以下步骤,看看上面给出的代码是如何工作的 -
将上面给出的HTML代码保存为服务器根文件夹中的modal_login_password.html文件。
以http://localhost/modal_login_password.html打开此HTML文件,输出显示如下。
当您单击第一个选项时,您将获得一个弹出窗口,您可以在其中输入用户名和密码。 单击“确定”后,将执行回调函数,显示输入的凭据。
当您单击第二个选项时,将出现一个弹出窗口,您可以在其中输入密码,单击“确定”后,将执行回调函数,显示输入的密码。