开发者

Help on how to link this current script to a radio button

As the title states I need some help on how to link this Jquery script for a show / hide effect to a radio button selection.

HTML

<tr>
<td><input type="radio" name="es_custom_reg" value="Y" /></td>
<td>Yes</td>
<td><input type="radio" name="es_custom_reg" value="N" /></td>
<td>No</td>
</tr>

Javascript

<script src="scripts/jquery.js" type="text/javascript"></script>

<script type="text/javascript">
      $(document).ready(function(){

   $('#slide').hid开发者_如何学运维e();

      $('a').click(function(){

   $('#slide').show('slow');

   });

   $('a#close').click(function(){
     $('#slide').hide('slow');
  })

    });
</script>


Try this:

$(function() {
    $('#slide').hide();
    $(':radio[name=es_custom_reg]').click(function() {
        var value = $(this).val();
        if (value === 'Y') {
            $('#slide').show('slow');
        } else if (value === 'N') {
            $('#slide').hide('slow');
        }
    });
});

And here's a demo.


use selector

jQuery("input[name='es_custom_reg']") this will give you reference to both the radio buttons. Use each.

jQuery("input[name='es_custom_reg']").each to loop through these two selections and then on the condition of .html()=='yes' execute your code.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜