0

你好

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也会检查下一个隐藏的

4

6 回答 6

1

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

于 2013-01-21T12:09:03.337 回答
0

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

现场演示

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

我建议您设置隐藏字段的值,而不是使用隐藏检查。

$(this).next(':hidden').val("true");
于 2013-01-21T12:07:04.727 回答
0

You can't check a hidden-type input. it is expecting a value, so the value could be 1 if previous is cecked or 0 if not checked.

于 2013-01-22T10:24:17.090 回答
0

你可以试试这个

JS代码

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

演示

于 2013-01-21T12:46:27.880 回答
0

after use the folowing code

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

and changing hidden input to another radio because it now work and by adding

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

for every answer input to be above degrees radio it work successfully.

but in the last question it's not work or check degree input :(

于 2013-01-22T22:44:27.733 回答
0

它应该是..

 $('[id^=answerid_]').on('change', function() {
    $(this).next().prop('checked', true);
    return false;
 });
于 2013-01-21T12:08:25.323 回答