繁体   English   中英

选中另一个隐藏的单选按钮

[英]Checked Another hidden radio Button

你好

我在尝试选择另一个时会选择隐藏的无线电input

<div class="questions">
<div class="questions_title">
    <span> Q : What Are you doing now ?</span>
</div>                       
<div class="answers">           
  <script>
      $('#answerid_').on('checked', function() {
         $('#degres_').prop('checked', true);
         return false;
      });
  </script>

  <div class="field">
   <input type="radio" value="1915" id="answerid_1" name="answerid_1" class="required">
   <input type="hidden" value="0" id="degres_1" name="degres_1">
   <span class="questions_label">Working. </span>
  </div>
  <div class="field">
   <input type="radio" value="1916" id="answerid_2" name="answerid_1">
   <input type="hidden" value="1" id="degres_2" name="degres_1">
   <span class="questions_label">Playing.</span>
  </div>
  <div class="field">
   <input type="radio" value="1917" id="answerid_3" name="answerid_1">
   <input type="hidden" value="2" id="degres_3" name="degres_1">
   <span class="questions_label">not Sleeping </span>
  </div>
  <div class="field">
   <input type="radio" value="1918" id="answerid_4" name="answerid_1">
   <input type="hidden" value="3" id="degres_4" name="degres_1">
   <span class="questions_label">Nothing.</span>
  </div>

</div>

我需要=>当选择任何答案时,也将根据下一个隐藏degree进行检查

您无法检查隐藏类型的输入。 但是,您可以检查单选类型的不可见输入(使用display:none样式)。

您需要通配符来附加事件和更改事件。

现场演示

$('[id^=answerid_]').on('change', function() {
        $(this).next(':hidden').prop('checked', true);
        return false;
});

建议您不要设置“隐藏字段”的值,而不要使用“隐藏字段的检查”。

$(this).next(':hidden').val("true");

它应该是..

 $('[id^=answerid_]').on('change', function() {
    $(this).next().prop('checked', true);
    return false;
 });

你可以试试这个

JS代码

$('[id^=answerid_]').on('change', function() {
        $(this).siblings('[id^=degres_]').prop('checked', true);
        alert($(this).siblings('[id^=degres_]').prop('checked'));
   return false;
});

演示

您无法检查隐藏类型的输入。 它需要一个值,因此如果选择上一个,则该值为1;如果未选中,则该值为0。

使用以下代码后

$('[id^=answerid_]').on('change', function() { $(this).siblings('[id^=degres_]').prop('checked', true); //alert($(this).siblings('[id^=degres_]').prop('checked')); return false; });

并将隐藏的输入更改为另一个收音机,因为它现在可以工作并通过添加

style="margin-left: -16px; position: absolute;"

对于每个高于无线电度数的答案输入,它都可以成功工作。

但在最后一个问题中它不起作用或检查学位输入:(

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM