2012-02-24 12 views
0

enter code here私の要件は、ページ上に画像とチェックボックスを表示しています。チェックボックスがオンになっているときと、マウスが画像をjover実行する必要があります。Jqueryは、チェックボックスがオンになっている場合にのみ実行する必要があります

チェックボックスをチェックアウトし、マウスのホバーはjqueryのは、実行すべきではありません画像上でされている場合....

私のコードは次のように..です

$(document).ready(
function() 
    { 
    $("#box img").click(
      function() 
       { 

        var sr=$(this).attr("src");      
        //alert(sr); 
        $("#box2 img").fadeOut("slow",function(){ 
        $("#box2").html("<img src='"+sr+"' style='opacity:0.30'/>"); 
        $("#box2 img").fadeTo("slow",1); 
        }); 


       } 
     ); 
     $("#box img").hover(
      function() 
      { 
       $(this).css({'z-index' : '10','border':'4px solid white'}); 
       $(this).animate({ 
       marginTop: '-110px', 
      marginLeft: '-110px', 
      top: '50%', 
      left: '50%', 
      width: '200px', 
      height: '200px'   
      },200); 
      }, 

今私がする必要がありますこの機能を実行する]チェックボックスがで...

+1

詳細情報が必要です。 jqueryを実行したいと言っているときはどういう意味ですか?あなたが意味するものをよりよく理解するために見ることができるいくつかのコードがありますか? – kinakuta

+0

私はちょうど質問のコードを追加しました。 –

答えて

0
$('#image_1').mouseover(function() { 
    if ($('#checkbox_1').is(':checked').length == 1) 
    { 
    // do stuff 
    } 
}); 
1

チェックされている場合にのみ、私は右、あなただけの特別な場合には(jQueryを使って)いくつかのJavaScriptコードを実行したいと思いますか?

ので、あなたがあなたの書類準備の部分でこれを配置する必要がありid="pix"

id="check"と画像でチェックボックスがあるとします。私はあなたがしたいと思う何

$('#pix').mouseover(function(){ 
    if($('#check').is(':checked')){ 
    //your code is here or function call 
    } 
}); 
1

は次のとおりです。

$('#image').hover(function() { 
if ($('#checkbox').is(':checked')) { 
    //Your code to do what ever you want on entry 
} 
}, function() { 
if ($('#checkbox').is(':checked')) { 
    //Your code to do what ever you want on exit 
} 
}); 
0

次のようなものがあります:

 

<input type="checkbox" id="chk_1" name="chkbox[]" value="" /> 
<img id="img_1" src="some_image.jpg" /> 

<script type="text/javascript"> 
$(document).ready(function() { 
    $("img[id^='img_']").mouseover(function() { 
     var id = $(this).split("_")[1]; 
     if($("input[id='chk_"+id+"']").is(":checked")) { 
      //run something 
     } 
    }); 
}); 
</script> 
 
関連する問題