如果我点击单选按钮,颜色变为黄色,但如果我双击它,我想要它的原始颜色,即灰色。 我应该怎么做?
JS
$(document).ready(function() {
$('input:radio').change(function() {
var $this = $(this);
$this.closest('.box').find('div.highlight').removeClass('highlight');
$this.closest('.q').addClass('highlight');
});
});
CSS
.q {
background: #ccc;
margin: 10 px;
}
.highlight {
background: #FC0;
}
HTML
<div class="box">
<div class="q">
<input type="radio" id="1" name="11" />
<label for 1>Radio Button1</label>
</div>
<div class="q">
<input type="radio" id="2" name="11" /`enter code here`>
<label for 1>Radio Button2</label>
</div>
</div>
最佳答案
使用dblclick和点击事件
<script>
$(document).ready(function(){
$('input:radio').click(function(){
var $this = $(this);
$this.closest('.box').find('div.highlight').removeClass('highlight');
$this.closest('.q').addClass('highlight');
})
.dblclick(function(){
var $this = $(this);
$this.closest('.box').find('div.highlight').removeClass('highlight');
$this.closest('.q').removeClass('highlight');
});
});
</script>
关于javascript - 如何在 jquery 中的 dbclick 上更改单选按钮的原始颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36908987/