如何使div可以单击?

<部门&gt&书信电报;span>上海&lt/span&gt&书信电报;span>男&lt/span&gt&lt/部门>

对于上面这样的div,当鼠标打开时,它应该成为cursor:pointer,当单击时,激发一个

javascript函数,如何做这项工作

编辑:当鼠标打开时,如何更改div的背景色

再次编辑:如何使第一个跨距的宽度为120px?在firefox中似乎不起作用

给它一个类似“某物”的ID,然后:

var something=document.getElementById('something');
something.style.cursor='pointer';
something.onclick=function(){
//做点什么。。。
};

更改背景颜色(根据您更新的问题):

something.onmouseover=function(){
this.style.backgroundColor='red';
};
something.onmouseout=函数(){
this.style.backgroundColor='';
};

发表评论