javascript如何设置字体效果
时间:2021-06-18 来源:互联网
今天PHP爱好者给大家带来在javascript中,可以使用style属性设置字体效果,语法格式“对象.style.属性=属性值”。Style对象代表一个单独的样式声明。可从应用样式的文档或元素访问Style对象。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function over(obj){
obj.style.backgroundColor="blue";
obj.style.color="white";
}
function out(obj){
obj.style.backgroundColor="";
obj.style.color="";
}
function win(){
p1.style.fontWeight="Bold";//粗体
p2.style.fontStyle="Italic";//斜体
p3.style.textDecoration="underline";//下划线
p4.style.textDecoration="line-through";//删除线
}
function qs(){
p1.style.fontWeight="normal";
p2.style.fontStyle="normal";
p3.style.textDecoration="none";
p4.style.textDecoration="none";
}
</script>
</head>
<body οnlοad="win();">
<table border="1" cellspacing="0" width="234" height="77">
<tr align="center" id="t1" οnmοusemοve="over(this);" οnmοuseοut="out(this);">
<td width="52"> </td>
<td width="65">商品</td>
<td width="95">价格(元)</td>
</tr>
<tr align="center" id="t2" οnmοusemοve="over(this);" οnmοuseοut="out(this);">
<td>A 商场</td>
<td>S 商品</td>
<td>100</td>
</tr>
<tr align="center" id="t3" οnmοusemοve="over(this);" οnmοuseοut="out(this);">
<td>B 商场</td>
<td>S 商品</td>
<td>80</td>
</tr>
</table>
<p id="p1">阿帕奇</p>
<p id="p2">阿帕奇</p>
<p id="p3">阿帕奇</p>
<p id="p4">阿帕奇</p>
<p id="p5" οnmοusemοve="qs();">鼠标移到此处撤销 阿帕奇样式</p>
<p id="p6">阿帕奇</p>
</body>
</html>
在很多情况下,都需要对网页上元素的样式进行动态的修改。在JavaScript中提供几种方式动态的修改样式,下面将介绍方法的使用、效果、以及缺陷。
1、使用obj.className来修改样式表的类名。
2、使用obj.style.cssTest来修改嵌入式的css。
3、使用obj.className来修改样式表的类名。
4、使用更改外联的css文件,从而改变元素的css
以上就是javascript如何设置字体效果的详细内容,更多请关注php爱好者其它相关文章!
-
删除百度网盘kernel.dll怎么做-应该如何操作才能删除百度网盘kernel.dll 2025-05-13
-
快速恢复bmm.dll文件丢失的方法-如何自动修复bmm.dll丢失问题 2025-05-13
-
热血江湖dbghelp.dll丢失怎么办-如何解决热血江湖dbghelp.dll丢失问题 2025-05-13
-
如何处理winpe下一点分区就蓝屏-winpe下一点分区就蓝屏怎么处理 2025-05-13
-
怎么样才能还原别人打码的图片-如何还原别人打码的图片 2025-05-13
-
蓝屏代码0xC0000221一键修复-电脑蓝屏提示代码0xC0000221怎么办 2025-05-13