有关如何将此当前脚本链接到单选按钮的帮助

时间:2010-09-15 16:43:02

标签: javascript jquery

正如标题所述,我需要一些帮助来解决如何将这个Jquery脚本链接到一个单选按钮选择的显示/隐藏效果。

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').hide();

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

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

   });

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

    });
</script>

2 个答案:

答案 0 :(得分:1)

使用选择器

jQuery(“input [name ='es_custom_reg']”)这将为您提供两个单选按钮的引用。使用每个。

jQuery(“input [name ='es_custom_reg']”)。每个循环遍历这两个选项,然后在.html()=='yes'的条件下执行你的代码。

希望这有帮助。

答案 1 :(得分:1)

试试这个:

$(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');
        }
    });
});

here's a demo