当前位置:网站首页>原生js动态添加元素
原生js动态添加元素
2022-06-25 15:36:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>原生js动态添加元素</title>
<style>
.phone {
width: 200px;
height: 30px;
}
ul {
width: 200px;
border: 1px solid #eee;
text-align: right;
}
ul li{
list-style: none;
height: 50px;
line-height: 50px;
padding-right: 20px;
border-right: 2px solid #999;
}
ul li:hover {
color: #f00;
border-right: 2px solid #f00;
}
/* .circle1 {
width: 492px;
height: 499px;
border-radius: 50%;
background: #f00;
display: flex;
align-items: center;
justify-content: center;
}
.circle2 {
width: 260px;
height: 434px;
border-radius: 50%;
background: #fff;
} */
</style>
</head>
<body>
<div class="container">
<form action="" id="form">
</form>
<ul id="parentUI">
<li>你好</li>
<li>关于我们</li>
<li>帮助中心</li>
</ul>
</div>
<script>
var formId = document.getElementById("form");
// 创建元素input
var inputPhone = document.createElement("input");
// 设置input的属性
inputPhone.setAttribute("class","phone");
inputPhone.type = "text";
inputPhone.value = "请输入手机号码";
formId.appendChild(inputPhone);
// js动态添加li
var ul = document.getElementById("parentUI");
var li = document.createElement("li");
li.setAttribute("class","list");
li.innerHTML = "联系我们";
ul.appendChild(li);
</script>
</body>
</html>
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/152106.html原文链接:https://javaforall.cn
边栏推荐
- Binocular 3D perception (I): preliminary understanding of binocular
- Globally unique key generation strategy - implementation principle of the sender
- Finally, we can figure out whether the binding event in the tag is bracketed or not
- (2) Relational database
- Source code analysis of nine routing strategies for distributed task scheduling platform XXL job
- MySQL modify field statement
- Netlogo learning
- Why do I need message idempotence?
- JSON module dictionary and string conversion
- Pytest测试框架笔记
猜你喜欢
JMeter reading and writing excel requires jxl jar
MySQL transaction characteristics and implementation principle
免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!
剑指 Offer 09. 用两个栈实现队列
Resolve Visio and office365 installation compatibility issues
appium服务的启动与关闭踩坑记录
解析数仓lazyagg查询重写优化
Install Kali extension 1: (kali resolution problem)
[paper notes] poly yolo: higher speed, more precise detection and instance segmentation for yolov3
TFIDF与BM25
随机推荐
股票开户用什么app最安全?知道的给说一下吧
04. binary tree
Source code analysis of nine routing strategies for distributed task scheduling platform XXL job
Sword finger offer II 091 Paint the house
Internal class learning notes
Thread - learning notes
[paper notes] semi supervised object detection (ssod)
Data feature analysis skills - correlation test
Efficient pytorch: how to eliminate training bottlenecks
Cloning and importing DOM nodes
JS中的==和===的区别(详解)
剑指 Offer 06. 从尾到头打印链表
Multithreading, parallelism, concurrency, thread safety
Agent and classloader
通过客户经理的开户链接开股票账户安全吗?
Start using markdown
MySQL修改字段语句
Download and installation tutorial of consumer
Mapbox map - inconsistent coordinate system when docking GIS layers?
数据类型的内置方法