标签:class .class htm text doctype type att set back
1、el.setAttribute(‘class‘,‘abc‘);
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta charset="utf-8" />
<title>setAttribute(‘class‘, ‘abc‘)</title>
<style type="text/css">
.abc {
background: red;
}
</style>
</HEAD>
<BODY>
<div id="d1">test div</div>
<script>
var div = document.getElementById(‘d1‘);
div.setAttribute("class", "abc");
</script>
</BODY>
</HTML>
2、el.setAttribute(‘className‘, ‘abc‘)
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta charset="utf-8" />
<title>setAttribute(‘className‘, ‘abc‘)</title>
<style type="text/css">
.abc {
background: red;
}
</style>
</HEAD>
<BODY>
<div id="d1">test div</div>
<script>
var div = document.getElementById(‘d1‘);
div.setAttribute("className", "abc");
</script>
</BODY>
</HTML>
3、el.className = ‘abc‘;
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta charset="utf-8" />
<title>el.className = ‘abc‘</title>
<style type="text/css">
.abc {
background: red;
}
</style>
</HEAD>
<BODY>
<div id="d1">test div</div>
<script>
var div = document.getElementById(‘d1‘);
div.className = ‘abc‘;
</script>
</BODY>
</HTML>
标签:class .class htm text doctype type att set back
原文地址:http://www.cnblogs.com/qfdy123/p/7881171.html