【发布时间】:2015-12-22 22:19:13
【问题描述】:
丹麦克朗
" id="radio2" value="75" />我有一堆由while循环生成的div条目,所以我想实现这个:当点击条目内的输入时,我想要改变条目div的背景图像,但是如果我在另一个条目div中选择另一个收音机..我'希望所有以前的更改(例如以前的背景更改)都消失并更改当前 div 的背景..这是我尝试做的也许你可以提供帮助..这是下面的 jquery
$("input").click(function() {
$(this).parent("div").toggle(function() {
$(this).parent("div").css("background", "url(images/div_bg_hover.png)");
}, function() {
$(this).parent("div").css("background", "url(images/div_bg.png)");
});
有些东西出了故障..我的意思是代码 inst' 工作在所有..有人可以帮助我吗?谢谢
这两个我都试过了:
$("input").click(function() {
$("input").each(function() {
if (this.checked) {
$(this).parent("div").addClass("highlight");
}
else {
$(this).parent("div").removeClass("highlight");
}
});
});
与
$("input").click(function() {
$("input").each(function() {
if (this.checked) {
$(this).parent("div").css("background", "url(images/div_bg_hover.png)");
}
else {
$(this).parent("div").css("background", "url(images/div_bg.png)");
}
});
});
由于某种原因,它根本不工作,没有改变背景,也许它必须对上面的代码做一些事情,这里是完整的脚本:
<script type="text/javascript">
$(document).ready(function() {
$(".left_navigation a:last").toggleClass('bolder');
$("input").each(function() {
var element_value = $(this).val();
$(this).prev("p").append(" " + element_value + ",-");
});
$("input").click(function() {
$("input").each(function() {
if (this.checked) {
$(this).parent("div").addClass("highlight");
}
else {
$(this).parent("div").removeClass("highlight");
}
});
});
});
</script>
【问题讨论】:
标签: jquery user-interface hover radio-button