Html 在文本框/标签上显示复选框值

Html 在文本框/标签上显示复选框值,html,symfony,twig,Html,Symfony,Twig,我有一个使用单选按钮生成数据列表的代码: <div class="inline-radio"> {% for a in TimeInfo %} <div class="row radio-row full-width no-padding"> <label class="radio-label-multiline font-weight-normal no-padding no-margin" for="slot_308395561"&

我有一个使用单选按钮生成数据列表的代码:

 <div class="inline-radio">
   {% for a in TimeInfo %}
     <div class="row radio-row full-width no-padding">
      <label class="radio-label-multiline font-weight-normal no-padding no-margin" for="slot_308395561">
        <div class="columns small-1 width20 no-margin no-padding">
          <input id="slot_308395561" name="form[slots]" required="required" value="" data-value="308395561" checked="checked" type="radio">
        </div>
     <div class="columns small-11 no-margin no-padding" id="slot_label_308395561"><span>{{ a.slotStartTime }} at {{ a.c.address}}</span></div></label></div>
   {% endfor %}
 </div>

{TimeInfo%中的%
{{a.slotStartTime}}在{a.c.address}}
{%endfor%}

我想在标签或文本框中显示选中复选框的值。我尝试使用javascript,但没有显示结果。

您正在将所有单选按钮的值设置为空白字符串:
value=“”
。这没有多大意义,尤其是因为您希望在其他地方显示所选单选按钮的值

将其值设置为
a
的某些属性:

{% for a in TimeInfo %}
    // ...
    <input type="radio" ... value="{{ a.value }}" />
{% endfor %}
最后一个逻辑错误。您正在将每个单选按钮设置为选中的
,但是,一次只能选中一个单选按钮

{% for a in TimeInfo %}
    // ...
    <input type="radio" ... {% if a.someProperty %}checked{% endif %} /> // assuming a is a PHP object and someProperty is boolean
    // the presence of the checked attribute is the same as
    // checked="checked" == checked="true" == checked="ducks"
{% endfor %}
{%in-TimeInfo%}
// ...
//假设a是PHP对象,someProperty是布尔值
//选中属性的存在与
//checked=“checked”==checked=“true”==checked=“ducks”
{%endfor%}

您正在将所有单选按钮的值设置为空字符串:
value=”“
。这没有多大意义,尤其是因为您希望在其他地方显示所选单选按钮的值

将其值设置为
a
的某些属性:

{% for a in TimeInfo %}
    // ...
    <input type="radio" ... value="{{ a.value }}" />
{% endfor %}
最后一个逻辑错误。您正在将每个单选按钮设置为选中的
,但是,一次只能选中一个单选按钮

{% for a in TimeInfo %}
    // ...
    <input type="radio" ... {% if a.someProperty %}checked{% endif %} /> // assuming a is a PHP object and someProperty is boolean
    // the presence of the checked attribute is the same as
    // checked="checked" == checked="true" == checked="ducks"
{% endfor %}
{%in-TimeInfo%}
// ...
//假设a是PHP对象,someProperty是布尔值
//选中属性的存在与
//checked=“checked”==checked=“true”==checked=“ducks”
{%endfor%}


它似乎不是细枝代码,而是生成的HTML。你能给我们更多的细枝代码吗?你到底想实现什么?您是否正在使用
表单
组件?先生@JovanPerovic,我想显示所选单选按钮的值。我使用的是
表单组件
你能显示你的控制器/表单代码吗?它似乎不是细枝代码,而是生成的HTML。你能给我们更多的细枝代码吗?你到底想实现什么?您是否正在使用
表单
组件?先生@JovanPerovic,我想显示所选单选按钮的值。我正在使用
Form
组件。你能显示你的控制器/表单代码吗?我已经在下面的JSFIDLE[link]()上尝试了你的代码,但仍然不起作用。很抱歉,我的第一条评论应该是()@momori14。你需要在你的小提琴中包含jQuery。这是一个运行中的jQuery版本@momori14解决您的问题是否顺利?是的,很抱歉刚刚接受了您的答案。非常感谢您的帮助。我已经在下面的JSFIDLE[link]()上尝试了your代码,但它仍然不起作用。很抱歉,我的第一条评论应该是()@momori14。您需要在您的FIDLE中包含jQuery。这是一个运行中的jQuery版本@momori14解决您的问题是否顺利?是的,很抱歉刚刚接受了您的答案。非常感谢你的帮助。