本教程操作环境: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高级教程】
以上就是javascript如何设置字体效果的详细内容。