首先需要在页面引入jQuery1.8以上的任意版本,并引入layer.js。
<script>
$('#BtnLogin').on('click', function() {
layer.open({
title: false,
type: 1,
area: ['397px'],
closeBtn: 0,
shadeClose: true, //点击遮罩关闭
content: '<div style="width:397px; background-color:#fcfcfc"> <form method="post" action="../UserInfo/login"><div><p align="center"> 账号 <input id="username" name="username" type="text" οnblur="ck()" /> </p> <div align="center"> 密码 <input id="password" name="password" type="password" /><br/><input type="button" οnclick="ckidpwd()" style="margin-top:15px;height:40px; width:170px;"class="layui-btn layui-btn-normal" value="登录"/><input type="submit" id="tjlogin" style="display: none" /></div> </form> <a id="qqLoginBtn"></a>'
});
});
</script>
content
内容
-
类型:String/DOM/Array
content可传入的值是灵活多变的,不仅可以传入普通的html内容,还可以指定DOM,更可以随着type的不同而不同。
以上为部分参数,详细参数请查看官网:http://www.layui.com/doc/modules/layer.html
完整代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>layer弹出层</title><script type="text/javascript" src="jquery-1.8.2.min.js"></script><script type="text/javascript" src="layer/layer.js"></script></head><body><a href="#" id="BtnLogin" style="float: right;margin-top:350px; margin-right:950px;font-size:20px;">点击弹出弹出层<script>//弹出登录子窗口$('#BtnLogin').on('click', function() {layer.open({title: false,type: 1,area: ['397px'],closeBtn: 0,shadeClose: true, //点击遮罩关闭content: '<div style="width:397px; background-color:#fcfcfc"> <form method="post" action="../UserInfo/login"><div><p align="center"> 账号 <input id="username" name="username" type="text" οnblur="ck()" /> </p> <div align="center"> 密码 <input id="password" name="password" type="password" /><br/><input type="button" οnclick="ckidpwd()" style="margin-top:15px;height:40px; width:170px;"class="layui-btn layui-btn-normal" value="登录"/><input type="submit" id="tjlogin" style="display: none" /></div> </form> <a id="qqLoginBtn"></a>'});});</script></body></html>复制到本地的时候需要将上面绿色字体js地址修改为本地js地址效果图:jQuery1.82.js layer.js下载地址:链接:http://pan.baidu.com/s/1nuVmqRR 密码:l1tk - 原文链接:http://lovecry.wang/Original/details?random=b93229ea-ca61-4322-b666-3734c2e42553