用require和artTemplate做的简单提示框

//require用来加载js文件,artTemplate则用来解析html模板

代码打包了,需要用ngix或其它搭建前端服务器才能正确运行.

//主页index.html代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link type="text/css" rel="stylesheet" href="style.css">
</head>
<body>
<form>
请输入名字:<input> <br>
请输入密码:<input> <br>
    <input type="submit" value="提交">
</form>
<script id="dialog" type="text/html">
    <div id="title"><%=title%></div>
    <div id="content">
        <button>取消</button>
        <button>确定</button>
    </div>
</script>
<script type="text/javascript" src="../../lib/require.js" data-main="main.js"></script>
</body>
</html>

//main.js代码

require.config({
    baseUrl: "",
        shim: {
            jQuery: {
                deps: ['text','template']
            }
        },
        paths: {
        'text': "../../lib/text"  ,
        'jQuery': "../../lib/jquery-1.9.1"  ,
        'template': "../../lib/template"
    }
})
require(['DialogView'],function(DialogView){
      var dialogV = new DialogView();
      $("body").append(dialogV.el);
})

//dialog.js 对话框js代码

define(['jQuery','text!dialog.html'],function(a,b){
    return function(){
        var render = template.compile(b);
        this.el = render({title:"测试"});
    }
})


//dialogTpl.html 对话框模板代码

<div class="bg"></div>
<div id="dialog">
    <div id="title" style="font-size: 30px"><%=title%></div>
    <div id="content">
        <button>取消</button>
        <button>确定</button>
    </div>
</div>

//style样式代码

body{
    overflow: hidden;
}
#dialog{
    padding: 5px;
    border: 1px solid #000000;
    /*background-color: #808080;*/
    margin: 200px auto  ;
    width: 300px;
    position: relative;
    z-index: 100;
    background-color: white;
    -webkit-border-radius: 5px;
}
#title{
    text-align: center;
    line-height: 40px;
    background-color: darkgray;
    height: 40px;
    -webkit-border-radius: 5px;
}
#content{
    height:100px ;
    margin-top: 30px;
    /*background-color: greenyellow;*/
}
#content button:nth-child(1){
    float: left;
    margin-left:30px ;
}
#content button:nth-child(2){
    float: right;
    margin-right:30px ;
}
button{
    font-size: 28px;
    height:45px;
    width: 90px;
}
.bg{
    opacity: 0.4;
    top: 0;
    position: absolute;
    width: 100%;
    height: 100%;
    background-color:black;
}






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值