<style type="text/css">
.a{ background-color:#00cc00; height:100px; width:100px}
.b{background-color:#cccccc}
</style><body>
<div id='test' class='a'></div>
</body>我希望的效果是
当时鼠标移动到div上的时候
div的 className变成 "a b"
鼠标离开div的时候
div的className变成"a"怎么写?
.a{ background-color:#00cc00; height:100px; width:100px}
.b{background-color:#cccccc}
</style><body>
<div id='test' class='a'></div>
</body>我希望的效果是
当时鼠标移动到div上的时候
div的 className变成 "a b"
鼠标离开div的时候
div的className变成"a"怎么写?
解决方案 »
- 得到XML数据怎么拿到里面的内容,alert出来是object XMLdocument
- 请教:IE6下打开iframe页面,显示空白,该如何解决?
- 在一个元素点击后不执行获得焦点元素的失去焦点事件
- javascript 调用COOKIE 设置用户路径及作用域 ! 急!
- [急救啊!!!]不知道错在哪里,用JS的innerHTML写脚本后就不能AJAX动态加载内容,怎么回事
- 动态设置输入框<input>的name属性的值,弄了2天了,晕死
- easyui的问题
- 超级难问题,javascript读取服务器端文件,并显示进度条
- javascript能否完成这个功能?
- 急!!!多选列表的值怎么接收!!!!!!
- 时间格式不一样,怎么比较时间大小(在线等高手回复)谢谢
- js读取xml的问题
window.onload=function(){
var div=document.getElementById("test");
div.onmouseover=function(){this.className="a";};
div.onmouseout=function(){this.className="b";};
}
</script>
window.onload=function(){
var div=document.getElementById("test");
div.onmouseover=function(){this.className="a";};
div.onmouseout=function(){this.className="b";};
}
</script>
<style type="text/css">
.a{ background-color:#00cc00; height:100px; width:100px}
.b{ background-color:#cccccc; height:100px; width:100px}
</style> <body>
<div id='test' class='a'> </div>
</body>
鼠标放上去的时候是样式变成 "a b" 就象jq里面的addclass一样
鼠标移开的时候 变成"a" 象removeClass一样
window.onload=function(){
var div=document.getElementById("test");
div.onmouseover=function(){this.className="a b";};
div.onmouseout=function(){this.className="b";};
}注意样式b要写在a的后面
这就是直接附直
a,b是未知的 不能这么写
addClass: function(value) {
if (jQuery.isFunction(value)) {
return this.each(function(i) {
var self = jQuery(this);
self.addClass(value.call(this, i, self.attr("class")));
});
} if (value && typeof value === "string") {
var classNames = (value || "").split(rspace); for (var i = 0, l = this.length; i < l; i++) {
var elem = this[i]; if (elem.nodeType === 1) {
if (!elem.className) {
elem.className = value; } else {
var className = " " + elem.className + " ";
for (var c = 0, cl = classNames.length; c < cl; c++) {
if (className.indexOf(" " + classNames[c] + " ") < 0) {
elem.className += " " + classNames[c];
}
}
}
}
}
} return this;
}