当前位置:网站首页>DOM及其应用
DOM及其应用
2022-08-05 05:13:00 【长路漫漫 大佬为伴】
1.编写一个登录页面,在客户端检验用户名和密码是否符合规范。
账户为:123
密码为:456
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="https://www.baidu.com/" onsubmit="return fn()">
<input type="text" name="userName" />
<input type="password" name="passWord" />
<button type="submit" >点我</button>
</form>
<script>
function fn() {
var flag=true;
var myUserName = document.querySelectorAll("input")[0];
var myPassWord = document.querySelectorAll("input")[1];
if (myUserName.value == "123") {
if (myPassWord.value == "456") {
alert("验证成功");
return flag;
}
else {
flag = false;
alert("密码错误,请重新输入");
return flag;
}
}
else {
flag = false;
alert("用户名错误,请重新输入!");
return flag;
}
}
</script>
</body>
</html>
运行截图:

2.编写一个表格组件。要求二维表数据与表格显示分离,不使用任何框架。本题可作为课程考核开发项目。
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
window.onload = function(){
//增加行
var btn = document.getElementById("a");
btn.onclick = function(){
var table = document.getElementsByTagName("table")[0];
add(table,"tr");
}
//删除行
var a = document.getElementsByTagName("a");
for(var i=0;i<a.length;i++){
a[i].onclick =function(){
var parentTwo = this.parentNode.parentNode;
var parentThree = parentTwo.parentNode;
remove(parentTwo,parentThree);
}
}
//鼠标移动修改颜色
var tr = document.getElementsByTagName("tr");
for(var i=0;i<tr.length;i++){
tr[i].onmouseover = function(){
background(this,"red");
};
tr[i].onmouseout = function(){
background(this,"white");
}
}
};
//改变颜色的函数
function background(obj,target){
obj.style.background = target;
}
//删除的函数
function remove(two,three) {
three.removeChild(two);
}
//增加行中删除操作的函数
function remover(obj) {
var remove1=document.getElementById('table').childNodes[1];
var remove2=obj.parentNode.parentNode;
remove1.removeChild(remove2);
}
//增加行的函数
function add(parent,child) {
var newone=document.createElement("tr");//新增行
newone.onmouseover = function(){
background(this,"red");
};
newone.onmouseout = function(){
background(this,"white");
};
var newone1=document.createElement("td");
newone1.innerHTML="<td />";
newone.appendChild(newone1);
var newone2=document.createElement("td");
newone2.innerHTML="<td />";
newone.appendChild(newone2);
var newone3=document.createElement("td");
newone3.innerHTML="<a href='javascript:;' οnclick='remover(this)' >删除</a>";
newone.appendChild(newone3);
document.getElementById("table").childNodes[1].appendChild(newone);
}
</script>
</head>
<body>
<table border="1" width="50%" id="table">
<tr>
<th>学号</th>
<th>姓名</th>
<th>操作</th>
</tr>
<tr>
<td>001</td>
<td>张三</td>
<td><a href="javascript:;" >删除</a></td> <!--在删除按钮上添加点击事件 -->
</tr>
<tr>
<td>002</td>
<td>李四</td>
<td><a href="javascript:;" >删除</a></td> <!--在删除按钮上添加点击事件 -->
</tr>
</table>
<input id ="a" type="button" value="添加一行" /> <!--在添加按钮上添加点击事件 -->
</body>
</html>
运行截图:
边栏推荐
- A blog clears the Redis technology stack
- Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
- MySQL Foundation (1) - Basic Cognition and Operation
- [cesium] 3D Tileset model is loaded and associated with the model tree
- 【过一下14】自习室的一天
- [Decoding tools] Some online tools for Bitcoin
- 【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
- UVA10827
- Qt produces 18 frames of Cupid to express his love, is it your Cupid!!!
- Flutter学习5-集成-打包-发布
猜你喜欢
![LeetCode: 1403. Minimum subsequence in non-increasing order [greedy]](/img/99/41629dcd84e95eb3672d0555d6ef2c.png)
LeetCode: 1403. Minimum subsequence in non-increasing order [greedy]

Qt produces 18 frames of Cupid to express his love, is it your Cupid!!!

Redis哨兵模式配置文件详解

数据库 单表查询

使用二维码解决固定资产管理的难题

ESP32 485 Illuminance

Flutter真机运行及模拟器运行

Basic properties of binary tree + oj problem analysis
![[Study Notes Dish Dog Learning C] Classic Written Exam Questions of Dynamic Memory Management](/img/0b/f7d9205c616f7785519cf94853d37d.png)
[Study Notes Dish Dog Learning C] Classic Written Exam Questions of Dynamic Memory Management

Difference between for..in and for..of
随机推荐
ESP32 485 Illuminance
开发一套高容错分布式系统
人性的弱点
"PHP8 Beginner's Guide" A brief introduction to PHP
多线程查询结果,添加List集合
Flutter learning three-Flutter basic structure and principle
How to quickly upgrade your Taobao account to a higher level
【过一下15】学习 lstm的一周
【过一下11】随机森林和特征工程
redis复制机制
Day019 Method overriding and introduction of related classes
2022杭电多校第一场01
【过一下7】全连接神经网络视频第一节的笔记
1.3 mysql批量插入数据
Mvi架构浅析
Flutter TapGestureRecognizer 如何工作
1068 Find More Coins
电话溥功能
span标签和p标签的区别
Flutter学习三-Flutter基本结构和原理