简体   繁体   English

单选按钮值未显示

[英]Radio buttons values not showing

I have a form with two hidden fields that appear based on an answer to a previous input. 我有一个表单,其中包含两个基于先前输入答案的隐藏字段。 I'm having no problem getting these to appear with some JavaScript. 我没问题让它们与某些JavaScript一起出现。 However, I'm unable to get the values of my radio buttons inserted onto the page. 但是,我无法将单选按钮的值插入页面。 The following code: 如下代码:

<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>

Results in these inputs: 这些输入的结果:

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

Anybody have an idea as to why my radio button values are disappearing? 有人知道为什么我的单选按钮值消失了吗?

EDIT: Here is the CoffeeScript used to display the fields. 编辑:这是用于显示字段的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")

I believe I have found a solution: 我相信我已经找到了解决方案:

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

Try adding a closing input tag, or self close the input tag: 尝试添加结束输入标签,或自行关闭输入标签:

<input [ATTRIBUTES] ></input>
<input [ATTRBITUES] />

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

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