【发布时间】:2012-07-07 07:23:43
【问题描述】:
我有 3 个单选按钮,单击第一个按钮时应该调用一个图像。单击第二个按钮时,第一个图像应该消失,单击 3 第二个应该消失。我想用jquery来做。请帮帮我
【问题讨论】:
-
@SanketKotak,这个问题很差。您应该提供更多细节、一些代码或一些个人努力的暗示。
标签: jquery html phpmyadmin
我有 3 个单选按钮,单击第一个按钮时应该调用一个图像。单击第二个按钮时,第一个图像应该消失,单击 3 第二个应该消失。我想用jquery来做。请帮帮我
【问题讨论】:
标签: jquery html phpmyadmin
你可以在demo看到代码示例
这里是示例代码。 但是我同意每个人的观点,您应该发布一些示例代码来表明您正在做一些思考!
div{
height:50px;
width:50px;
}
.yellow{
background-color:yellow
}
.green{
background-color:green;
}
.blue{
background-color:blue;
}
.red{
background-color:red;
}
<ul>
<li><input type='radio' id='1' name='change'><label>red</label></li>
<li><input type='radio' id='2' name='change'><label>blue</label></li>
<li><input type='radio' id='3' name='change'><label>green</label></li>
</ul>
<div id='show' class='yellow'></div>
$(document).ready(function(){
$('ul>li>input').change(function(index){
console.log($(this));
var id = $(this).attr('id');
console.log(id);
var cssClass = 'yellow';
switch(id)
{
case '1':
cssClass = 'red';
break;
case '2':
cssClass = 'blue';
break;
case '3':
cssClass = 'green';
break;
}
console.log(cssClass);
$('#show').removeClass().addClass(cssClass);
});
});
【讨论】: