【问题标题】:Converting checkbox to select (perl)将复选框转换为选择(perl)
【发布时间】:2011-03-11 08:29:12
【问题描述】:

之前:

<input type='checkbox' name='killerFeature' id='killerFeature' 
    <%= param('killerFeature') ? ' checked' : ''%> 
/>

现在:

<select name="killerFeature" id="killerFeature" class="select">
    <option value="1">Enable</option>
    <option value="0">Disable</option>
</select>

如何在现在的选择中插入相同的选中(我猜现在应该是“选择”?)条件?

这是一个 perl 应用程序,使用 Mojolicious 网络框架构建。

非常感谢您的帮助!

【问题讨论】:

    标签: perl forms mojo mojolicious


    【解决方案1】:

    是的,应该选择条件(selected="selected"),但我相信您已经从其他帖子中发现了这一点:)

    <select name="killerFeature" id="killerFeature" class="select">
        <option value="1" selected="selected">Enable</option>
        <option value="0">Disable</option>
    </select>
    

    另外,从我看到的情况来看,还有一种方法可以像下面的示例一样为输入创建选择:

    <%= input 'test', type => 'text' %>
    

    所以应该是这样的:

    <%== param('killerFeature') eq $my_var ? ' selected="selected"' : ''; %>
    

    您需要将以上内容替换为您当前的变量和字段名称。

    GL:)

    【讨论】:

    • W3C 要求有左手和右手。而不是 'selected' 它应该是 'selected="selected"'。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 2021-07-08
    • 1970-01-01
    • 2020-02-05
    相关资源
    最近更新 更多