jQuery Mobile和HTML5开发App推广注册页

jQuery Mobile和HTML5的组合可以直接开发web版的app,所以用到我当前app中的推广注册页的编写是很恰当的,其实只要你熟悉html4+jquery的组合开发,那么html5+jqueryMobile你会立刻上手。

html5比html4多了很多的标签,特别是多媒体这块有了很好的支持,但是如果只是做一般的web手机页面,那么多数标签是用不上的,JqueryMobile与jquery的不同点就在一些事件名称上,当然这里封装的也是html5的原生事件,还要说一个关于html5提倡的一个规则,这里jquerymobile是遵循了这个规则的, html5里面给标签增加几个新的权限特征, data-role="page"、  data-role="header" 、data-role="content"、 data-role="footer",  为什么html5会增加这几个特征,我觉得多是为支持web版手机app开发而出的,因为html5提倡开发web版app只创建一个html页,然后每个段落=一个新页面,下面我贴一段几个div标签组合成的一个整体页面,当然它们都各自加了上面的特性。

<!--data-role="page"表示这个是一个html5单独页面,可以从另外一个加了page特性的div打开它 -->
<div data-role="page" id="phoneRegister">
<!--data-role="header"这个特性你想成APP的navigationbar -->
<div data-role="header" id="heardId"></div>
<!--data-role="content"内容里面展示页面内容的,必入你放一张表在这个标签里面展示 -->
<div data-role="content"> </div>
<!--data-role="footer"这个特性你想成APP的tabbar -->
<div data-role="footer"> </div>
</div>

上面的div其实就组合成了一个html5页面了。

一、页面注意事项

1. 首先html5标准页面申明,页面中的第一行代码与html4不一样,

html5:<!DOCTYPE>

html4:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

此标签的作用是告诉浏览器支持什么html规范。

2.引入jquery和jquerymobile的支持库

<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">

<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>

<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>

上面的库都是直接通过链接地址引入的,等会我直接贴代码,如果想看效果,可以直接copy代码到一个html页面直接打开就可以运行。

二、整页代码

<!DOCTYPE>
<html>
<head>
 <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
 <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
 <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
$(document).on("pagecreate", function () {
  var contentHeight = document.body.clientHeight;
  var header = contentHeight * 0.1;
  var content = contentHeight * 0.75;
  var footer = contentHeight * 0.15;
  $("#phoneRegister #heardId").css({ 'height': header + 'px', 'background': '#4dbb49', 'line-height': header + 'px' });
  $("#phoneRegister #contentId").css({ 'height': content + 'px' });
  $("#phoneRegister #footerId").css({ 'height': footer + 'px', ' font-size': '70px', 'line-height': footer + 'px' });
  var flag = false;
  setInterval(function () {
    if (flag == false) {
      $("#presentGiftTitle").css({ 'color': 'rgb(255, 0, 0)' });
      flag = true;
      return;
    }
    if (flag == true) {
      $("#presentGiftTitle").css({ 'color': 'rgb(255, 102, 0)' });
      flag = false;
      return;
    }
  }, 100);
});
//当页面初始化完毕后
$(document).on("pageshow", "#commonRegister", function () { // 当进入页面二时
  var contentHeight = document.body.clientHeight;
  var header = contentHeight * 0.1;
  var content = contentHeight * 0.75;
  var footer = contentHeight * 0.15;
  $("#commonRegister #heardId").css({ 'height': header + 'px', 'background': '#4dbb49', 'line-height': header + 'px' });
  $("#commonRegister #contentId").css({ 'height': content + 'px' });
  $("#commonRegister #footerId").css({ 'height': footer + 'px', 'font-size': '70px', 'line-height': footer + 'px' });
});
$(document).on("pageinit", "#phoneRegister", function () {
  $("#phoneRegisterClick").on("tap", function () {
    var name = $("#phoneRegister #name").val();
    var password = $("#phoneRegister #password").val();
    var re = /^(13[0-9]{9})|(15[89][0-9]{8})$/;
    if (!re.test(name)) {
      alert("请输入正确的手机号!")
      return;
    }
    if (password.length < 6) {
      alert("密码不能小于6位数")
      return;
    }
    var checkBox = $("#phoneRegister #Checkbox1");
    if (!checkBox.is(":checked")) {
      alert("请阅读条例!")
      return;
    }
    //开始发送手机验证
    alertVerifyCodeMethod();
  });
});
$(document).on("pageinit", "#commonRegister", function () {
  $("#commonRegisterClick").on("tap", function () {
    var name = $("#commonRegister #name").val();
    var password = $("#commonRegister #password").val();
    var phonenumber = $("#commonRegister #phoneNumber").val();
    var safemail = $("#commonRegister #safeMail").val();
    var re = /^(13[0-9]{9})|(15[89][0-9]{8})$/;
    var mre = /\w@\w*\.\w/;
    if (name.length < 6) {
      alert("注册用户名不能小于6位数!")
      return;
    }
    if (password.length < 10) {
      alert("密码不能小于10位数")
      return;
    }
    if (!re.test(phonenumber)) {
      alert("请输入正确的手机号!")
      return;
    }
    if (!mre.test(safemail)) {
      alert("请输入正确的邮箱!")
      return;
    }
    var checkBox = $("#commonRegister #Checkbox1");
    if (!checkBox.is(":checked")) {
      alert("请阅读条例!")
      return;
    }
    shareAjaxMethord(0, name, password, phonenumber, safemail);
  });
});
function alertVerifyCodeMethod() {
  if (document.all) {
    document.getElementById("alertVerifyCodeBox").click();
  }
  else {
    var e = document.createEvent("MouseEvents");
    e.initEvent("click", true, true);
    document.getElementById("alertVerifyCodeBox").dispatchEvent(e);
  }
}
function shareAjaxMethord(index, name, password, phone, email) {
  $.ajax({
    type: "POST",
    async: false,
    dataType: "text",
    data: "&sgin=" + index + "&name=" + name + "&password=" + password + "&phone=" + phone + "&email=" + email,
    url: "ajaxMediumPage.ashx",
    success: function (returnDate) {
      if (index == 0) {
        if(returnDate=="1")
        {
          alert("注册成功!");
        }
        else
        {
          alert("注册失败!");
        }
      }
      else if (inedx == 1) {
      }
      else {
      }
    }
  });
}
</script>
</head>
<body>
  <!-- 这个div data-role="page"表明它是一个页面 -->
  <div data-role="page" id="phoneRegister">
    <div data-role="header" id="heardId">
  <div style="margin-left:20px; font-size:17px;  font-weight:bold"><a href="#pagetwo" style="color:white; text-decoration:none;">首页>手机在线注册</a></div>
    </div>
    <div data-role="content" id="contentId">
        <section id="posts">
          <article class="post">
            <header>
              <h4 id="presentGiftTitle">使用手机后注册后立刻赠送100乐币!</h4>
            </header>
            <aside>
              手机号:
              <input id="name" type="text" placeholder="请输入注册帐号!" />
            </aside>
            <aside>
              密  码:
              <input id="password" type="password" placeholder="请输入注册密码!" />
            </aside>
            <aside>
              <div style="margin-left:-15px;">
                <div style="width: 20px;  height: 20px; float:left; margin-top:5px;"> <input id="Checkbox1" style="width: 18px; height: 18px;" type="checkbox" /></div>
                <div style="margin-left:40px;"><h5>打勾注册表示你同意本公司的服务条例!</h5></div>
              </div>
            </aside>
            <aside style="margin-top:20px;">
              <div id="phoneRegisterClick" style="text-align: center; border: 1px solid #666666; background: #4dbb49; color: white; height: 30px; width: 100px; line-height: 30px; ">立即注册<a href="#dialog" id="alertVerifyCodeBox" data-rel="dialog" style="display:none"></a> </div>
            </aside>
            <aside style="margin-top:20px;">
              <div style="float:right"><a href="#commonRegister" data-transition="flip">普通注册(非手机)</a></div>
            </aside>
            <footer></footer>
          </article>
        </section>
    </div>
    <div data-role="footer" id="footerId" style="background:#666666;">
      <div style="width:100%;height:90%;text-align:center;">
        <div style="font-size:13px; height:25%;text-decoration:none;margin-top:0px;padding-top:0px; line-height:16px;">电话:400-900-8000</div>
        <div style="font-size: 13px; height: 25%; text-decoration:none;margin-top: 0px; padding-top: 0px; line-height:16px;">渝ICP备000000-c号</div>
        <div style="font-size: 13px; height: 25%;text-decoration:none; margin-top: 0px; padding-top: 0px; line-height: 16px;">版权所有</div>
      </div>
    </div>
  </div>
<!-- 这个div data-role="page"表明它是一个页面 -->
  <div data-role="page" id="commonRegister">
    <div data-role="header" id="heardId">
      <div style="margin-left:20px; font-size:17px;  font-weight:bold"><a href="#pagetwo" style="color:white; text-decoration:none;">首页>普通用户在线注册</a></div>
    </div>
    <div data-role="content" id="contentId">
        <section id="posts">
          <article class="post">
            <aside>
              帐 号:
              <input id="name" type="text" placeholder="请输入注册帐号!" />
            </aside>
            <aside>
              密  码:
              <input id="password" type="password" placeholder="请输入注册密码!" />
            </aside>
            <aside>
              手机号:
              <input id="phoneNumber" type="text" placeholder="请输入手机号!" />
            </aside>
            <aside>
              安全邮箱:
              <input id="safeMail" type="text" placeholder="请输入安全邮箱!" />
            </aside>
            <aside>
              <div style="margin-left:-15px;">
                <div style="width: 20px;  height: 20px; float:left; margin-top:5px;"> <input id="Checkbox1" style="width: 18px; height: 18px;" type="checkbox" /></div>
                <div style="margin-left:40px;"><h5>打勾注册表示你同意本公司的服务条例!</h5></div>
              </div>
            </aside>
            <aside style="margin-top:20px;">
              <div id="commonRegisterClick" style="text-align:center;border:1px solid #666666; background:#4dbb49;color:white;height:30px;width:100px; line-height:30px;">立即注册 </div>
            </aside>
            <aside style="margin-top:20px;">
              <div style="float:right"><a href="#phoneRegister" data-transition="flip">手机注册(手机号)</a></div>
            </aside>
            <footer></footer>
          </article>
          </section>
    </div>
    <div data-role="footer" id="footerId" style="background:#666666;">
      <div style="width:100%;height:90%;text-align:center;">
        <div style="font-size:13px; height:25%;text-decoration:none;margin-top:0px;padding-top:0px; line-height:16px;">电话:400-900-8000</div>
        <div style="font-size: 13px; height: 25%;text-decoration:none; margin-top: 0px; padding-top: 0px; line-height:16px;">渝ICP备000000-c号</div>
        <div style="font-size: 13px; height: 25%;text-decoration:none; margin-top: 0px; padding-top: 0px; line-height: 16px;">版权所有</div>
      </div>
    </div>
  </div>

  <div data-role="page" id="dialog" style="padding-top:auto">
    <div data-role="header" id="heardId" style="background:#4dbb49">
      <h1>输入验证码</h1>
    </div>
    <div data-role="content" id="contentId">
      <aside>
        验证码:
        <input id="verifyCode" type="text" placeholder="请输入验证码!" />
      </aside>
      <aside>
        <div id="inputVerifyCodeDiv" style="width: 100px; height: 30px; background: #4dbb49; color:white; line-height:30px; float:right; text-align:center">确 定</div>
      </aside>
    </div>
    <div data-role="footer" id="footerId" style="background:#4dbb49">
      <h1></h1>
    </div>
  </div>
</body>
</html>

上面的代码直接copy到一个html页面可以运行。

以上所述是小编给大家介绍的jQuery Mobile和HTML5开发App推广注册页,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!

(0)

相关推荐

  • jquery mobile事件多次绑定示例代码

    新手新手,初学js,html,css,jq就不断麻烦 复制代码 代码如下: $(document).on("pageinit",function(){ $("XXX").bind() }) 这种绑定方法会在整个document每pageinit一次,就对xxx进行的某一事件进行绑定,而pageinit事件什么时候会触发,具体要如何解决,可以看链接 http://rubiks.ph/jquery-mobile-events-firing-multiple-times/

  • jquery.hotkeys监听键盘按下事件keydown插件

    jquery.hotkeys文件下载:  http://xiazai.jb51.net/201405/yuanma/jquery_hotkeys(jb51.net).rar 参照了一下它的文档用法,我们可以这样使用: 复制代码 代码如下: <script src="jquery-1.4.1.min.js" type="text/javascript"></script>    <script src="jquery.hotke

  • jQuery Mobile 触摸事件实例

    触摸事件在用户触摸屏幕(页面)时触发. 必须引入jQuery库和jQuery Mobile库,如下: <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js">

  • jQuery事件的绑定、触发、及监听方法简单说明

    如果你在写文章或者 Demo,为了简单,你当然可以用事件监听函数,以及那些事件对象提供的方法等.但在实际中,有一些方法和属性是有兼容性问题的,所以我们会使用 jQuery 来消除兼容性问题. 下面简单的来说一下 jQuery 中事件的基础操作. 绑定事件和事件代理 在 jQuery 中,提供了诸如 click() 这样的语法糖来绑定对应事件,但是这里推荐统一使用 on() 来绑定事件.语法: .on( events [, selector ] [, data ], handler ) event

  • jquery mobile的触控点击事件会多次触发问题的解决方法

    jquery mobile 对手势触控提供了如下几个事件监听: 复制代码 代码如下: tap  当用户点屏幕时触发taphold 当用户点屏幕且保持触摸超过1秒时触发swipe 当页面被垂直或者水平拖动时触发.这个事件有其相关联的属性,分别为scrollSupressionThreshold, durationThreshold, horizontalDistanceThreshold, and verticalDistanceThresholdswipeleft 当页面被拖动到左边方向时触发s

  • js和jquery实现监听键盘事件示例代码

    项目中要监听键盘组合键CTRL+C,以便做出对应的响应.查了一些方法但是其兼容性和稳定性不是很高,最终得到如下方法,经测试在Firfox.Chrome.IE中均可以使用. 一.使用javascript实现 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script> function keyListener(e

  • 浅析jQuery Mobile的初始化事件

    jQuery Mobile 包括一个初始化事件,该事件甚至会先于 jQuery 的 document.ready 事件进行加载.jQuery Mobile 实际上在文档对象本身上触发其初始化事件,第一个触发的事件是mobileinit. 当Jquery Mobile开始执行时,他就会在document对象上触发mobileinit 事件,因为mobileinit事件是在加载后马上触发,所以你需要在Jquery Mobile加载之前绑定你的事件处理函数,所以我建议你如下安排你的js引用顺序 <sc

  • jquery-mobile基础属性与用法详解

    本文实例讲述了jquery-mobile基础属性与用法.分享给大家供大家参考,具体如下: 写在前面 本文是根据w3c 学习轨迹,自己研习过程中记录下的笔记,只供自己学习轨迹记录之用,不喜勿喷. 0. 引入库 引入对应的文件: <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> <script src="

  • jQuery-mobile事件监听与用法详解

    本文实例讲述了jQuery-mobile事件监听与用法.分享给大家供大家参考,具体如下: 触摸事件 - 当用户触摸屏幕时触发(敲击和滑动) 滚动事件 - 当上下滚动时触发 方向事件 - 当设备垂直或水平旋转时触发 页面事件 - 当页面被显示.隐藏.创建.加载以及/或卸载时触发 一.初始化事件 1. ready 事件 页面加载完成 $(document).ready(function(){ //your code here... }); 2. 页面加载完成事件二 pageinit $(docume

  • 让input框实现类似百度的搜索提示(基于jquery事件监听)

    挺炫的一个效果,百度和谷歌好像已实现好多年了,我以为在网上能轻易找到代码来实现这个效果.真正遇到这个需求,发现还真找不到.于是自己动手写这个效果,由于我是把效果整合到我的整套框架里,所以没有进行单独的封装. 需求:实现带提示的input框,类似百度搜索,有改动的时候去获取常用关键词,数据来源于系统数据库,支持鼠标选择或键盘选择 思路:框架一贯思路,通过class作为监听入口,通过data作为数据传递:通过监听input和propertychange事件实现实时的改动监听,input是主流,pro

  • jQuery绑定事件监听bind和移除事件监听unbind用法实例详解

    本文实例讲述了jQuery绑定事件监听bind和移除事件监听unbind用法.分享给大家供大家参考,具体如下: 这里分别采用后bind(eventType,[data],Listener)//data为可选参数,one()该方法绑定的事件触发一次后自动删除,unbind(eventType,Listener), 实例: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w

  • jquery-mobile表单的创建方法详解

    本文实例讲述了jquery-mobile表单的创建方法.分享给大家供大家参考,具体如下: 一.注意事项 1. <form> 元素必须设置 method 和 action 属性 2. 每个表单元素必须设置唯一的 "id" 属性. 该 id 在站点的页面中必须是唯一的. 这是因为 jQuery Mobile 的单页面导航模型允许许多不同的"页面"同时呈现. 3. 每个表单元素必须有一个标记(label). 请设置 label 的 for 属性来匹配元素的 i

随机推荐