当前位置:网站首页>JS-DOM元素对象
JS-DOM元素对象
2022-08-11 02:31:00 【(-^_^-)】
获取文本和HTML内容的DOM属性
innerHTML--------节点内的文本或者HTML标签------------嵌入HTML之中(要求只能文本禁止标签)
innerText——节点内的文本没有HTML标签——仅支持IE浏览器
textContent——节点内的文本没有HTML标签——除支持IE浏览器其他
value——表单控件中的文本——input
使用DOM调整样式(color backgroundColor border 等 和CSS有大小写区别)

用JS代码设置字体加粗和样式:


用JS代码设置字体 (使用一个函数 不同的字体的设置关键点是this)

JS代码设置字体大小



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网页</title>
<script src="js/e.js" type="text/javascript"></script>
</head>
<body>
<!-- 联系的函数 -->
<div id="1">
<p>Lorem ipsum dolor sit.</p>
<p>Lorem ipsum dolor sit.</p>
<p>Lorem ipsum dolor sit.</p>
<p>Lorem ipsum dolor sit.</p>
<p>Lorem ipsum dolor sit.</p>
<p>Lorem ipsum dolor sit.</p>
</div>
<div id="2">
Font:
<input type="radio" id="serif" name="1"><!-- name相同为了只能选一个而不是复选 -->
Serif
<input type="radio" id="fantasy" name="1">Fantasy
<input type="radio" id="monosapce" name="1">Monosapce
<br>
Style:
<input type="checkbox" id="bold"><!-- checked表示默认选中 -->
Bold加粗
<input type="checkbox" id="italic">Ttalic倾斜
</div>
</body>
</html>function bold(){
var a=document.getElementById('1');//添加的位置
if(this.checked){
a.style.fontWeight="bold";
}else{
a.style.fontWeight="normal";
}
}
function italic(){
var a=document.getElementById('1');//添加的位置
if(this.checked){
a.style.fontStyle="italic";
}else{
a.style.fontStyle="normal";
}
}
function fontset(){
var a=document.getElementById('1');//添加的位置
a.style.fontFamily=this.id; //当前窗口
//字体大小增加2pt 原来的字体大小 与12二选其一 实现12的设置及
var oldSize =parseInt(a.style.fontSize) ||12;
a.style.fontSize=(oldSize+2)+"pt";//转换成字符 每次选中会实现字体的扩大
}
window.onload=function(){
document.getElementById('bold').onclick=bold;//上面连成一句
document.getElementById('italic').onclick=italic;
document.getElementById('serif').onclick=fontset;
document.getElementById('fantasy').onclick=fontset;
document.getElementById('monosapce').onclick=fontset;
}
边栏推荐
猜你喜欢

117. 本地开发好的 SAP UI5 应用部署到 ABAP 服务器时,中文字符变成乱码的原因分析和解决方案

Tomca启动闪退问题如何解决

Please talk about for...in and for...of in JS (below)

深度学习-第二次
![[oops-framework] Template project [oops-game-kit] Introduction](/img/09/29faf7626b0bc66e4d016a15e80b8b.png)
[oops-framework] Template project [oops-game-kit] Introduction

The practice of alibaba data synchronization component canal

CSAPP Data Lab

Logstash日志数据写入异常排查问题总结

Detailed explanation of new features of ES advanced array function syntax

一次简单的 JVM 调优,拿去写到简历里
随机推荐
如何开展性能测试,你知道吗?
经典面试题 之 GC垃圾收集器
超声图像三维拼接-可视化选择,总体思路
英伟达 GPU 架构简史
隐私计算融合应用研究
【PHP】入门知识
FPGA learning column (xinlinx) serial communication -
ifconfig与ip命令的比较
如何解决高度塌陷
入职数字ic设计后的一些工作心得
13.cuBLAS开发指南中文版--cuBLAS中的Level-1函数copy()和dot()
leetcode 739. Daily Temperatures 每日温度(中等)
0图中等 LeetCode565. 数组嵌套
Summary of Logstash log data write exception troubleshooting
《如何戒掉坏习惯》读书笔记
Ninjutsu_v3_08_2020-安全渗透系统安装
Lianshengde W801 series 5-WeChat applet and W801 Bluetooth communication routine (read notes)
Detailed explanation of the opkg of OpenWrt
ASEMI整流桥GBJ5010参数,GBJ5010电压,GBJ5010电流
Pytorch/TensorFlow/Numpy常用函数汇总