CSS样式还原问题,或样式过渡保存问题? 我有一个span从一堆样式里动态获得了一个样式,然后在后面的程序里临时让它用了另一个样式,用完后还要让它还原到原来的样式,但我不知道它原来是什么样式,这个怎么弄啊?能不能像变量赋值一样:c=a,a=b,a=c.弄个中间过渡的变量存放一下啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 span.setAttribute("oldStyle","xxx")span.style.xxx = span.getAttribute("oldStyle")采用伪属性保存 可以,表格的光棒效果也是这样实现的<table width="100%"><tr style="background-color:#666" onmouseover="oldcolor = this.style.backgroundColor;this.style.backgroundColor='#999'" onmouseout="this.style.backgroundColor=oldcolor"><td>test</td></tr><tr style="background-color:#666" onmouseover="oldcolor = this.style.backgroundColor;this.style.backgroundColor='#999'" onmouseout="this.style.backgroundColor=oldcolor"><td>test</td></tr><tr style="background-color:#666" onmouseover="oldcolor = this.style.backgroundColor;this.style.backgroundColor='#999'" onmouseout="this.style.backgroundColor=oldcolor"><td>test</td></tr></table> 哦,原来这就叫光棒效果啊……贴个直接用classname的代码 <select onchange="setStyle(this.value)"> <option>请选择</option> <option value="cls1">样式红</option> <option value="cls2">样式蓝</option> <option value="cls3">样式黄</option> </select> <BR><span id="sp" style="width:100px; height:100px;" class="cls0">span</span><BR><INPUT id="btn" TYPE="button" VALUE="还原上一样式" ONCLICK="turnback()" disabled><SCRIPT LANGUAGE="JavaScript"><!-- var oldStyle; function setStyle(para){ oldStyle = sp.className; sp.className = para; btn.disabled = false; } function turnback(){ sp.className = oldStyle; btn.disabled = true; }//--></SCRIPT> 你这个xxx是不是只是单个属性啊?如果我的样式群都像.style1{color:red;font-size:12px;......}等多个属性怎么办? 可不可以xxx=document.getElementID("span").classname然后document.getElementID("span").classname=xxx [JQUERY]关于单击行的问题 关于jquery异步提交的问题,jquery高手多多指点! 求嵌套div 拖放的解决方案 高手帮我看看下面的函数调出什么问题了? div层跟踪对象。可以跟踪button,但是不能跟踪div对象。 在一个函数中如何防止另一个函数被执行 关于在模式对话匡中翻页的问题 简单!送分!-->如何批定义变量 请教关于层的浮动的问题! 请教高手这是使用什么加密的。 nicEdit编辑器扩展问题--高手们帮帮忙 关于继承机制
span.style.xxx = span.getAttribute("oldStyle")采用伪属性保存
可以,表格的光棒效果也是这样实现的<table width="100%">
<tr style="background-color:#666" onmouseover="oldcolor = this.style.backgroundColor;this.style.backgroundColor='#999'" onmouseout="this.style.backgroundColor=oldcolor"><td>test</td></tr>
<tr style="background-color:#666" onmouseover="oldcolor = this.style.backgroundColor;this.style.backgroundColor='#999'" onmouseout="this.style.backgroundColor=oldcolor"><td>test</td></tr>
<tr style="background-color:#666" onmouseover="oldcolor = this.style.backgroundColor;this.style.backgroundColor='#999'" onmouseout="this.style.backgroundColor=oldcolor"><td>test</td></tr>
</table>
贴个直接用classname的代码 <select onchange="setStyle(this.value)">
<option>请选择</option>
<option value="cls1">样式红</option>
<option value="cls2">样式蓝</option>
<option value="cls3">样式黄</option>
</select>
<BR>
<span id="sp" style="width:100px; height:100px;" class="cls0">span</span>
<BR>
<INPUT id="btn" TYPE="button" VALUE="还原上一样式" ONCLICK="turnback()" disabled>
<SCRIPT LANGUAGE="JavaScript">
<!--
var oldStyle;
function setStyle(para){
oldStyle = sp.className;
sp.className = para;
btn.disabled = false;
}
function turnback(){
sp.className = oldStyle;
btn.disabled = true;
}
//-->
</SCRIPT>
然后document.getElementID("span").classname=xxx