2011-10-18 14 views
0

select divは、隣にある入力タグの値がゼロの場合にのみ表示されます。私はこれをどのようにして行うのですか?ここ はここjsfiddle http://jsfiddle.net/mdanz/xdFkJ/jquery hide入力タグの値に依存する要素

<style type="text/css"> 
.select { 
overflow:hidden; 
display:block; 
background-color:red; 
width:100px; 
height:100px; 
} 

</style> 
<script type="text/javascript"> 
$(function() { 
var value = $('.row').val(); 

    if(value!=0) { 
    $('.select').hide(); 

    } 

}); 
</script> 

<div class='select'></div><input type='text' class='row' value='0' /> 
<div class='select'></div><input type='text' class='row' value='1' /> 
<div class='select'></div><input type='text' class='row' value='1' /> 
<div class='select'></div><input type='text' class='row' value='0' /> 

答えて

4
$(function() { 
    $('input.row').change(function() { 
    var $this = $(this); 
    if ($this.val() != "0") { 
     $this.prev().hide(); 
    } else { 
     $this.prev().show(); 
    } 
    }); 

    $('input.row').trigger('change'); 
}); 

あるフィドルhttp://jsfiddle.net/jfhartsock/xdFkJ/3/です。これは、入力を変更するときにdivを非表示にすることにも注意してください。あなたはこのように行うことができます

0

$(function() { 
    $("input.row").change(function(){ 
     if($(this).val()=="0"){ 
     $(this).prev().show(); 
     }else{ 
     $(this).prev().hide(); 
     } 

    }); 

}); 
0

使用。

$(function() { 

    $(".select").each(function() { 
     var value = $(this).next('.row').val(); 

     if(value!=0) 
      $(this).hide(); 

    }); 
}); 

私はあなたにmootoolsを設定しました。私のfiddleを参照してください:

関連する問題