单选按钮值未显示

时间:2014-09-25 17:24:25

标签: javascript html forms

我有一个表单,其中包含两个隐藏字段,这些字段基于对先前输入的回答而显示。我可以通过一些JavaScript显示这些内容没有问题。但是,我无法将我的单选按钮的值插入到页面上。以下代码:

<div id="hidden-fields" style="display:none">
    <div class="sixteen columns input-wrap">
      <input id="delivery-instructions" name="ship_delivery_instructions" type="text" placeholder="Special delivery instructions?">
    </div>
    <div class="sixteen columns input-wrap">
      <label>Preferred dropoff time
        <input type="radio" class="radio-button" name="ship_dropoff_time" value="1">1 - 3 PM
        <input type="radio" class="radio-button" name="ship_dropoff_time" value="6">6 - 8 PM
      </label>
    </div>
  </div>
</div>

这些输入的结果:

<input type="radio" class="radio-button" name="ship_dropoff_time" value>
<input type="radio" class="radio-button" name="ship_dropoff_time" value>

有人知道为什么我的单选按钮值会消失吗?

编辑:以下是用于显示字段的CoffeeScript。

events:
  "keyup #zip": "check_zip_code"

check_zip_code: (e) ->
  currentZip = e.currentTarget.value
  if eligibleZipCodes.indexOf(currentZip) == -1
    @makeFieldsInvis()
  else
    @makeFieldsVis()

makeFieldsInvis: ->
  $("#hidden-fields").css("display", "none")
  $("#delivery-instructions").val("")
  $(".radio-button").each(-> $(this).attr('checked', false))

makeFieldsVis: ->
  $("#hidden-fields").css("display", "block")

1 个答案:

答案 0 :(得分:1)

我相信我找到了解决方案:

这是我的JSFiddle:http://jsfiddle.net/pmbbLkzk/

尝试添加结束输入标记,或者自行关闭输入标记:

<input [ATTRIBUTES] ></input>
<input [ATTRBITUES] />
相关问题