我的文字无法点击
鉴于我将我的输入放在标签标签
中html代码
<label for="mvaas_api_log_server_information"><input checked="checked" id="server_information_portal" name="server_information" type="radio" value="portal">
portal
</label>
<label for="mvaas_api_log_server_information"><input id="server_information_register" name="server_information" type="radio" value="register">
register
</label>
</div>
haml代码
= f.label "Choose Server" , class:'col-sm-2 control-label no-padding-right', for: 'form-field-1'
.col-sm-5
- %w(portal register).each_with_index do |server_type, i|
= f.label :server_information do
- if server_type == @mvaas_api_log.server_information
= radio_button_tag :server_information, server_type, true
- else
= radio_button_tag :server_information, server_type
= server_type
答案 0 :(得分:0)
标签的for
属性必须与您要触发的输入的id
匹配,如下所示:
<label for="server_information_portal"><input checked="checked" id="server_information_portal" name="server_information" type="radio" value="portal">
portal
</label>
<label for="server_information_register"><input id="server_information_register" name="server_information" type="radio" value="register">
register
</label>
</div>
如果for
属性不匹配,则浏览器无法知道标签带有哪些输入。