<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.red {
border: solid 1px red;
width: 200px;
height: 100px;
text-align: center;
line-height: 100px;
margin: auto;
}
.blue {
border: solid 1px blue;
width: 200px;
height: 100px;
text-align: center;
line-height: 100px;
margin: auto;
}
</style>
<script type="text/javascript" src="../../js/system.js"></script>
</head>
<body>
<div id="a" class="red">
hello js,,
</div>
<div id="b">
html js2 ,,
</div>
<input type="button" value="点我变红" id="bitRed">
<script type="text/javascript">
36 //id名为b的元素的样式随着id名为a的元素的样式的变化而变化
var clasName = comm.getAttr($$("a"), "class"); //获取id名为a的元素的class样式,并把它赋给clasName;
comm.setAttr($$("b"), "class", clasName); //给id为b的元素设置class样式为clasName;
$$("bitRed").onclick = function () {
// $$("a").setAttribute("class","blue");
comm.setAttr($$("a"), "class", "blue");
var clasName = comm.getAttr($$("a"), "class");
comm.setAttr($$("b"), "class", clasName);
}
</script>
</body>
</html>
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxwAAADsCAIAAABxHzfbAAAKDUlEQVR4nO3cS2/bVh7G4fN9u0h6n6+R9D6LLor6q9RJ7/U+aRwPZuJMMhMnTneVZ2HX0EgiTcv6m6Le5wFBSIeHFG0IOD9YStoZAAA31sa+AQC4ttZstqpt/bfl5t7hAHBLbrLyQQ9RBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAFlFFEVEFQBZRRRFRBUAWUUURUQVAF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qIKgCyiiiKiCoAsoooiogqALKKKIqIKgCyiiiKiCoAsoooiogqALKKKIqIKgCyiiiKiCoAsoooiogqALKKKIqIKgCyiiiKiCoAsoooiogqALKKKIqIKgCyiiiKiCoAsoooiogqALKKKIqIKgCyiiiKiCoAsoooiogqALKKKIqIKgCyiiiKiCoAsoooiogqALBOKqtZa29Dttr/U3UObc/0b3AWiCoAs01rxNxsodVG1MCezq0QVAFmmtdz318l126WudUTVmagCIM20lntRNSGiCoAs01ruz+tk+btK7f+tHFz+5G6NCFt5kf6vT2UW1ZmoAiDNtFb85ZZaOLo8v+vByvkD72H4Daz9KjtAVAGQZVorfn/EjB5V/ZPTiCoAskxr0d+2qDrr/a8TkovqTFQBkGZa6/4WRlXXofCiOhNVAKSZ1tK/bVHVdQPX/UZ8z5fcpxtnogqALBNasrv+cd/ynOUJ8w/mD61RLQtRtfI6bcmQH234+CSIKgCyTHbJvlW38Lle12VFFQBMw2SX7Fu19p+1hl98+PhUiCoAskx51WariSoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKoqIKgCyiCqKiCoAsogqiogqALKIKorcNKoOjmZ7+7uwHRzNNvZLBWCLtWazVW3rvy0PjmZ3vnn78Ve/7sB255u3ugoAGEXb25999OUvf+yEv/39t2+/+3PsXykAkOgiqt6+fXt6ejr1/cdf/SqqAIBRXETVmzdvTk9Pp77/6MtfRBUAMIq2tz/78IufX79+fXJycuW+tdY/p7V2PufKmVfOGXKFhb2oAgDGchFVr169Ojk5uXLfllweXRhprV2OL8/psvBaK8/qucMPv/hZVAEAo2h7+7MPPv/pv8O01gZOmJ+5fFb/0StP6SKqAICxXETVf4ZprQ2c0DXzfHz+aNdI12APUQUAjKXt7c/e/+zHly9fvnjxYuW+59O6IXPmZ7bWLufPn7t8dOH680d79h98/pOoAgBGcRFV/+7WWhs+fjnYddZwC1cYckFRBQCMpe3tz9779Ifnz58fHx+v3LfWho+31haOXo5cjq/UdZ2ekeX9+5/9KKoAgFFcRNWzZ8+Oj49X7ltrw8fPC+nyaNec/pGF2Oo6a3kvqgCAsbS9/dm7n3z/r24935RaOXP+ac81h0zrOqXLe5/+IKoAgFFcRNU/b+Y8p84fLIzMDy6fsvLQ8hW6LrJAVAEAY2l7+7O79x/+o1tr7XK/8sGVkxdmntdS19OVI10vt+DdT74XVQDAKC6i6qhDa2358fKDy6cLIwuDKyf0H1r5sWPX3YoqAGAsbW9/dufeg6dPnx4eHk59L6oAgLFcRNWTJ08ODw+nvr97/6GoAgBGcRFVv+8EUQUAjOUiqh49evT48eOp7+/ceyCqAIBRtIOj2Ttfv7pz78HUt7v3H77z9auDo9nYv1IAIFE7Ozs7OJp9+92fO7ApKgBgLG3sGwAA2AWiCgBgA0QVAMAGiCoAgA0QVQAAGyCqAAA2QFQBAGyAqAIA2ABRBQCwAf8DSaEELmjNyW8AAAAASUVORK5CYII=" alt="" />
//js样式
/**
* Created by Ibokan on 2015/8/26.
*/
function $$(id) {
return document.getElementById(id);
}
var comm = {
setAttr: function (e, strName, strValue) { //e是元素名称 ,,strName是属性名称,,strValue是属性值。。
e.setAttribute(strName, strValue);
},
getAttr: function (e, strName) {
return e.getAttribute(strName);
}
}