style对象的cssText方法有哪些使用方法


当前第2页 返回上一页

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>控制div属性</title>

<style>

#outer{width:500px;margin:0 auto;padding:0;text-align:center;}

#div1{width:100px;height:100px;background:black;margin:10px auto;display:block;}

</style>

<script>

var changeStyle = function (elem, attr, value)

{

    elem.style[attr] = value

};

window.onload = function ()

{

    var oBtn = document.getElementsByTagName("input");

    var oDiv = document.getElementById("div1");

    var oAtt = ["width","height","background","display","display"];

    var oVal = ["200px","200px","red","none","block"];

  

    for (var i = 0; i < oBtn.length; i++)

    {

        oBtn[i].index = i;

        oBtn[i].onclick = function ()

        {

            this.index == oBtn.length - 1 && (oDiv.style.cssText = "");

            changeStyle(oDiv, oAtt[this.index], oVal[this.index])

        

    }

};

</script>

</head>

<body>

<div id="outer">

<input type="button" value="变宽" />

<input type="button" value="变高" />

<input type="button" value="变色" />

<input type="button" value="隐藏" />

<input type="button" value="重置" />

<div id="div1"></div>

</div>  

</body>

</html>

相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

相关阅读:

html与xhtml和xml有什么区别

iframe的子页面怎样操作父页屏蔽页面弹出层效果

以上就是style对象的cssText方法有哪些使用方法的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

html以及css的常用用法

html与css中2d转换模块

利用css的 border-image 实现锯齿形

style是什么意思

纯css实现tab页切换效果

html5和css3扁平化风格博客教程的资源分享

html5、css实现文字阴影效果实例分享

html、css和js的注释规范用法有哪些

css实现聚光灯效果的代码分享

react怎么写style

更多相关阅读请进入《cssText》频道 >>




打赏

取消

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

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

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

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

评论

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