重建已单击的按钮样式
Reestablishing a clicked button style
我需要一些帮助:我做了三个按钮,一旦我点击其中一个,它的样式应该通过Javascript改变。这是有效的。但应该会发生别的事情:一旦我再次点击按钮,旧的样式就会恢复。看看下面的代码:
function changeStyleOne(){
if(this.style.background != 'rgba(207,207,207,.8)'){
this.style.background = 'rgba(207,207,207,.8)';
this.style.boxShadow = '0 5px 20px rgba(0,0,0,.3) inset';
this.style.borderLeft = '0';
this.style.width = '99px';
button2.style.background = '-webkit-linear-gradient(bottom, #B9B9B9 0%, white 90%)';
button2.style.width = '98px';
button2.style.borderLeft = '1px solid white';
button2.style.boxShadow = '';
button3.style.background = '-webkit-linear-gradient(bottom, #B9B9B9 0%, white 90%)';
button3.style.width = '98px';
button3.style.borderLeft = '1px solid white';
button3.style.boxShadow = '';
displayContent1();
}else{
this.style.background = '-webkit-linear-gradient(bottom, #B9B9B9 0%, white 90%)';
this.style.boxShadow = '';
this.style.borderLeft = '1px solid white';
this.style.width = '98px';
}
}
这不起作用:当我再次点击按钮时,它不会恢复旧的样式。你知道为什么吗?
下面是一个简单的例子,
http://jsfiddle.net/LT4sQ/.class1 {
background: -webkit-linear-gradient(bottom, #B9B9B9 0%, white 90%);
box-shadow: none;
border-left: 1px solid white;
width: 98px;
}
.class2 {
background: rgba(207, 207, 207, .8);
box-shadow: 0 5px 20px rgba(0, 0, 0, .3) inset;
border-left: 0;
width: 99px;
}
function changeStyleOne(e) {
e.className = (e.className == "class1") ? "class2" : "class1";
}
这里有一个你可以学习的简单例子:
HTML:<button>Button 1</button>
<button>Button 2</button>
<button>Button 3</button>
CSS: .styled {
background: lightblue;
}
jQuery: $("button").click(function() {
$(this).toggleClass('styled');
});
演示相关文章:
- bootstrap在类更改时动画按钮样式
- 如何使用Jquery设置按钮样式
- 更改按钮样式但保存默认行为 - NativeScript
- 在 jQuery 幻灯片切换上更改按钮样式
- 更改 POST AngularJS 上的按钮样式
- javascript中一个按钮样式的两种字体类型
- jQuery禁用启用按钮样式
- 使用JavaScript自定义具有给定数据的按钮样式
- 是否有允许图例将每个系列设置为按钮样式的样式可供应用
- jQuery按钮样式仅应用于Datatable第一页中的按钮
- 如何使用 jQuery 更改引导按钮样式
- 如果填充了三个输入并且两个特定的输入相等,则会更改按钮样式;除非不删除“不等于”输入的值,否则它可以工作
- 使用angularjs更改按钮样式
- 不能将jquery UI按钮样式添加到所有按钮Codeigniter
- 基础下拉按钮样式不正确
- 重建已单击的按钮样式
- 如何使用JavaScript激活按钮样式
- 按钮样式元素的类冲突
- 使用https://twitter.com/intent/user?user_id=删除按钮样式
- jQuery移动按钮上的调用按钮(“刷新”)会破坏按钮样式