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爱好者其它相关文章!
-
钟薛高破产雪糕刺客时代终结,消费理性回归平价产品主导市场(钟薛高雪糕味道怎么样) 2025-07-09
-
币圈必备的行情软件推荐2025 2025-07-09
-
迷你世界旋转装置怎么做-迷你世界旋转门 2025-07-09
-
使命召唤手游本周活动有哪些-高达版本福利活动 2025-07-09
-
安卓用户必装的数字货币交易APP 2025-07-09
-
国际金价持续上扬创新高,金饰品克价突破千元心理关口(国际金价上涨) 2025-07-09