DKK
"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)");
});
何かが誤動作しています..私はコードがまったく機能していないことを意味します..誰かが私を助けることができますか?ありがとうございました
私はこれを両方試しました:
$("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>