添加以及删除className

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script>
window.onload=function(){ var oDiv=document.getElementById('di');
var oDiv2=document.getElementById('di1');
addClass(oDiv,'boee');
remove(oDiv2,'box2'); function addClass(obj,className)
{
if(obj.className==null)
{obj.className=className;}
else{
var arrClassName=obj.className.split(' ');
var _index=arrIndexOf(arrClassName,className );
if(_index==-)
{
obj.className+=' '+className;
}else{
} }
}
function arrIndexOf(arr,v){
for(var i=;i<arr.length;i++)
{
if(arr[i]==v)
{return i;} } return -; } function remove(obj,className){
if(className!=''){
var arrClassName=obj.className.split(' ');
var _index=arrIndexOf(arrClassName,className );
if(_index!=-)
{
arrClassName.splice(_index,);
obj.className=arrClassName.join(' ');
} }
}
};
</script>
</head>
<body>
<div class="box box2" id='di'>div1</div>
<div class="box box2" id='di1'>div2</div>
</body>
</html>
上一篇:Mac上安装Appium简介


下一篇:基于jQuery 的图片瀑布流实现