老师,绑定事件不知道什么原因报错了
HTML代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/css.css">
<script type="text/javascript" src="js/jq.js"></script>
<script type="text/javascript" src="js/js.js"></script>
</head>
<body>
<header>
<div class="title">
<div class="logo"></div>
<div class="text">
<span class="text1">慕课高铁客户服务中心</span>
<span class="text2">|</span>
<span class="text3">客户服务</span>
</div>
<div class="txt">
<p> 建议反馈<a href="#" class="p_margin">imooc@com</a></p>
<p>您好,请 <a href="#" class="p_margin">登录</a></p>
<p>| 注册</p>
<p class="p_margin"> 我的IMOOC </p>
<p class="arrow-down p_margin">
<div class="arrow-down_other">
<ul>
<li><a href="#">未完成订单</a></li>
<li><a href="#">已完成的订单(改/退)</a></li>
<li><a href="#">我的保险</a></li>
<li><a href="#">查看个人信息</a></li>
<li><a href="#">账户安全</a></li>
<li><a href="#">常用联系人</a></li>
<li><a href="#">重点旅客预约</a></li>
<li><a href="#">遗失物品查找</a></li>
<li><a href="#">服务查询</a></li>
<li><a href="#">投诉</a></li>
<li><a href="#">建议</a></li>
</ul>
</div>
</p>
</div>
<div class="tel">
</div>
<p class="tel_text">手机版</p>
</div>
</header>
<div class="banner">
<div class="banner_center">
<div class="banner_">您现在的位置:<span>客运首页 > 注册</span></div>
<div class="RegExp">
<div class="RegExp_title">账户信息</div>
<form>
<div class="item">
<span class="important">*</span>
<label for="username">用 户 名:</label>
<input type="text" name="" id="username">
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important">*</span>
<label for="userpass">登录密码:</label>
<input type="text" name="" id="userpass">
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important">*</span>
<label for="userpass_">确认密码:</label>
<input type="text" name="" id="userpass_">
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important">*</span>
<label for="name">姓 名:</label>
<input type="text" name="" id="name">
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important">*</span>
<label for="certificate">证件类型:</label>
<select>
<option>二代身份证</option>
<option>富二代证</option>
<option>高富帅证</option>
</select>
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important">*</span>
<label for="certificate_number">证件号码:</label>
<input type="text" name="" id="certificate_number">
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important"></span>
<label for="email"> 邮 箱:</label>
<input type="text" name="" id="email">
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important">*</span>
<label for="tel">手机号码:</label>
<input type="text" name="" id="tel">
</div>
<p class="item_"></p>
<br>
<div class="item">
<span class="important">*</span>
<label class="tourist">旅客类型:</label>
<select>
<option>会员</option>
<option>游客</option>
</select>
</div>
<p class="item_"></p>
<br>
<div class="item">
<input type="checkbox" name="" id="check">
<label for="check">我已阅读并同意遵守</label>
<a href="#">《中国铁路客户服务中心网站服务条款》</a>
</div>
<br><br>
<div class="item">
<input type="button" name="" value="下一步">
</div>
</form>
</div>
</div>
</div>
<footer></footer>
</body>
</html>
-------------------------------------------------
CSS代码
*{
padding: 0;
margin: 0;
}
p{
display: inline-block;
}
a{
text-decoration: none;
color: #fb7403;
}
ul{
list-style: none;
line-height: 28px;
font-size: 13px;
padding: 10px;
padding-left: 20px;
background-color: white;
}
ul>li:nth-child(2),ul>li:nth-child(3),
ul>li:nth-child(5),ul>li:nth-child(6),
ul>li:nth-child(8),ul>li:nth-child(9){
border-bottom:1px dashed #abadb3;
}
ul>li>a{
color: #abadb3;
}
.arrow-down{
border-left:10px solid transparent;
border-right:10px solid transparent;
border-top:12px solid #000000;
position: relative;
}
header{
background-color: #efefef;
height: 125px;
border-bottom: 1px solid #2487c9;
}
.banner{
height: 804px;
background-color: #ffffff;
border-bottom: 1px solid #2487c9;
}
footer{
height: 110px;
background-color: #dcdcdc;
}
header>.title{
width: 1258px;
margin: 0 auto;
}
header>.title>.logo{
width: 110px;
height: 130px;
background-image: url(../img/logo.png);
background-repeat: no-repeat;
background-position:0px 5px;
float: left;
}
header>.title>.text{
line-height: 125px;
width: 260px;
float: left;
}
header>.title>.text>.text1{
font-size: 18px;
font-weight: bold;
}
header>.title>.text>.text2{
font-size: 24px;
}
header .txt{
line-height: 132px;
float: left;
margin-left: 115px;
}
header .p_margin{
margin-left: 5px;
margin-right: 5px;
}
header .tel{
float: left;
width: 30px;
height: 45px;
margin-top: 42px;
margin-left: 40px;
background-image: url(../img/1.png);
background-size:50% 50%;
background-position: 50%;
background-repeat: no-repeat;
}
header .tel_text{
margin-top: 53px;
}
header .arrow-down_other{
width: 150px;
height: 330px;
border:1px solid #fb7403;
position: absolute;
top: 90px;
right: 560px;
display: none;
}
header .arrow-down_other.active{
display: block;
transition: all .5s;
}
.banner>.banner_center{
width: 1258px;
margin: 10px auto;
}
.banner>.banner_center>.banner_{
height: 34px;
text-align: left;
}
.banner>.banner_center>.banner_>span{
color: gray;
}
.banner>.banner_center>.RegExp{
height: 630px;
border:1px solid #fb7403;
border-radius: 10px;
}
.banner>.banner_center>.RegExp>.RegExp_title{
height:40px;
background-color:#fb7403 ;
color: white;
border-radius: 8px;
line-height: 40px;
text-indent: 10px;
margin-bottom: 60px;
}
.item{
width: 500px;
padding-left:300px;
}
.item>.important{
color: red;
}
.item>select{
padding-right: 10px;
width: 175px;
}
.item>input[type=button]{
background-color: #fb7403;
color: white;
border:none;
width: 250px;
height:40px;
border-radius: 8px;
margin-left: 200px;
cursor: pointer;
}
JS代码---------------------------------------------------------
$(function(){
var p=false;
$('.arrow-down').mouseover(function(){
if(p==false)
{
$('.arrow-down_other').addClass('active');
p=true;
}
else{
$('.arrow-down').mouseout(function(){
$('.arrow-down_other').removeClass('active');
p=false;
})
}
})
})
var username=document.querySelector('#username');
var userpass=document.querySelector('#userpass');
var name=document.querySelector('#name');
var certificate_number=document.querySelector('#name');
var email=document.querySelector('#email');
var tel=document.querySelector('#tel');
var test1=false;
var items=document.querySelectorAll('.item_');
username.onfocus=function(){
items[0].innerText="6-30位字母,数字或'_',字母开头";
items[0].style.color="red";
}
正在回答
你好,是因为获取元素的代码放在了$(function(){})文档载入事件的外面,DOM元素没有加载完就获取元素是获取不到的,所以会出现问题。
将代码全部放在载入事件中就可以:
可以重新测试下,祝学习愉快!
- 参与学习 人
- 提交作业 467 份
- 解答问题 4826 个
本路径带你通过系统学习HTML5、JavaScript、jQuery的进阶知识,不仅如此,还会学习如何利用组件化的思想来开发网页,知识点+案例,使得所学可以更好的得到实践。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星