js改变css样式的三种方法
- cssText=’’
div.style.cssText='width:600px;height:250px;';
- setProperty()
div.style.setProperty('width','700px');
- 使用css属性对应的style属性
div.style.width = "800px";
js两者交换的实例
- 背景交换
function myfunction(){
var one = document.getElementById('one');
if(one.style.backgroundColor=='pink'){
one.style.backgroundColor='blue';
}
else{
one.style.backgroundColor='pink';
}
}
选择器.style.backgroundColor=’’;
- 图片交换
function imgfunction(){
var image = document.getElementById('img');
if(image.src.indexOf('h-img08') >= 0){
image.src="image/image15/h-img07.jpg";
}
else{
image.src="image/image15/h-img08.jpg";
}
}