功能:为背景色和前景色为空的div标签添加背景色和前景色
.css(<link rel="stylesheet" type="text/css" href="css/src/main.css" />)
.greenredclass {
background: green;
color: red;
}
div标签
<div style="border:1px solid black" id="af15_content"> div标签中的内容</div>
按钮事件
<a class="button" onclick='$("#af15_content").addClass("greenredclass")'>增加背景色和前景色</a>
JavaScript方法(<script type="text/javascript" charset="utf-8" src="./appframework.js"></script>)
addClass: function(name) { if (name == nundefined) return this; for (var i = 0; i < this.length; i++) { var cls = this[i].className; var classList = []; var that = this; name.split(/s+/g).forEach(function(cname) { if (!that.hasClass(cname, that[i])) classList.push(cname); }); this[i].className += (cls ? " " : "") + classList.join(" "); this[i].className = this[i].className.trim(); } return this; },
重点在于
onclick='$("#af15_content").addClass("greenredclass")'
$("#div标签id").JavaScript方法("背景色前景色style")