javascript如何设置字体效果


本文摘自PHP中文网,作者醉折花枝作酒筹,侵删。

在javascript中,可以使用style属性设置字体效果,语法格式“对象.style.属性=属性值”。Style对象代表一个单独的样式声明。可从应用样式的文档或元素访问Style对象。

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

<%@ 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如何设置字体效果的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

javascript如何设置字体效果

更多相关阅读请进入《js设置字体样式》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...