欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JavaScript

程序员文章站 2022-03-08 22:54:52
...

JavaScript是一个脚本语言,解释执行(看一行执行一行)浏览器运行

今天先做了一个注册界面,代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script action="#">
        function checkFrom() {
            var input1=document.getElementById("username").value;
            if(name.length<6){
                alert("长度太短");
                return false;
            }
            var ps=document.getElementById("password").value;
            var reps=document.getElementById("repassword").value;
            if (ps!=reps){
                alert("2次输入的密码不一样");
                return false;
            }
            var phone=document.getElementById("mobile").value;
            /*1   3456789   9(0-9)  11位*/
            /*正则表达式*/
            if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone)){
                alert("手机格式不对");
                return false;
            }
        }
    </script>
</head>
<body>
<form action="#">
    <div>用户名:<input id="username" type="text"></div>
    <div>密码:<input id="password" type="password"></div>
    <div>确认密码:<input id="repassword" type="password"></div>
    <div>手机号:<input id="mobile" type="number"></div>
    <div><input type="submit" value="注册" onclick="checkFrom()"/></div>
</form>
</body>
</html>

效果如下:
JavaScript

轮播图实现带左右按钮控制焦点图片切换和自动播放效果

<!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>实现带左右按钮控制焦点图片切换</title>
<style type="text/css">
*{margin:0;padding:0;}
ul,li{list-style:none;}
img{border:0;}
.wrapper{
	width: 800px;
	margin: 0 auto;
	padding-bottom: 50px;
}
#focus{
	width: 800px;
	height: 280px;
	overflow: hidden;
	position: relative;
}
#focus ul{
	height: 380px;
	position: absolute;
}
#focus ul li{
	float: left;
	width: 800px;
	height: 280px;
	overflow: hidden;
	position: relative;
	background: #000;
}
#focus ul li div{
	position: absolute;
	overflow: hidden;
}
#focus .preBtn{
	width: 45px;
	height: 100px;	
	left: 0;
	top:90px;
	background:url(images/spirte.png) no-repeat 0 0;
	background-color:#000;
	cursor: pointer;
	opacity:0.4;
	filter:alpha(opacity=40);
}
#focus .nextBtn{
	width: 45px;
	height: 100px;
	right:0px;
	top:90px;
	background:url(images/spirte.png) no-repeat right top;
	background-color:#000;
	cursor: pointer;	
	opacity:0.4;
	filter:alpha(opacity=40);}
</style>

<!-- 请在此处添加javascript代码实现需求 -->
  <script type="text/javascript">
      var picArr=new Array();
      picArr[0]="images/01.jpg";
      picArr[1]="images/02.jpg";
      picArr[2]="images/03.jpg";
      picArr[3]="images/04.jpg";
      picArr[4]="images/05.jpg";
      var index=0;
      var timer=0;
      window.onload=showPic;
      function showNext() {
          clearTimeout(timer)
          showPic();

      }
      function showPic () {
          document.getElementById("pic").src=picArr[index];
          if(index<(picArr.length-1)){
              index++;
          }else{
               index=0;
              }
         setTimeout("showPic()",2000);
      }
  </script>

</head>

<body>
<div class="wrapper">
  <div id="focus">
    <ul>
      <li><a href="#" target="_blank"><img src="images/01.jpg" alt="" id="pic"/></a>
      <div class="preBtn" onclick="showPre()"></div>
      <div class="nextBtn" onclick="showNext()"></div> 
      </li>      
    </ul>     
  </div>
</div>
</body>
</html>

效果如下:
JavaScript
最后做了一个手机品牌左右交换的界面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function selectOne() {
            var leftS = document.getElementById("leftSelect");
            var options = leftS.options;

            var rightS = document.getElementById("rightSelect");

            for (var i = 0; i < options.length; i++) {
                var option1 =options[i];
                if (option1.selected) {
                    rightS.appendChild(option1);
                }
            }
        }
    </script>
</head>
<body>
<table width="400px" border="1px">
    <tr>
        <td>分类名称</td>
        <td><input type="text" value="手机数码"></td>
    </tr>
    <tr>
        <td>分类描述</td>
        <td><input type="text" value="手机数码"></td>
    </tr>
    <tr>
        <td>分类商品</td>
        <td>
            <div style="float: left">
                已有商品<br/>
                <select multiple="multiple" id="leftSelect" ondbclick="selectOne()">
                    <option>华为</option>
                    <option>小米</option>
                    <option>诺基亚</option>
                </select>
                <br/>
                <a href="#" onclick="selectOne()">&gt;&gt;</a>
                <a href="#" onclick="select0ne()">&gt;&gt;&gt;</a>
            </div>
            <div style="float: right">
                未选商品<br/>
                <select multiple="multiple" id="rightSelect" ondbclick="selectOne()">
                    <option>苹果</option>
                    <option>三星</option>
                    <option>oppo</option>
                </select>
                <br/>
                <a href="#" onclick="selectOne()">&lt;&lt;</a>
                <a href="#" onclick="selectOne()">&lt;&lt;&lt;</a>
            </div>
        </td>
    </tr>


</table>
</body>
</html>

效果如下:
JavaScript
JavaScript