单击标签不会打开选择 [英] click on label doesn't open select

查看:41
本文介绍了单击标签不会打开选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为,点击 label 或多或少会触发"相应表单元素上的点击.然而,当涉及到 select 时,这似乎不起作用.mousedown-on-selectfield"动画有效,但选择未打开.

I always thought, that a click on a label will more or less "trigger" the click on the according form-element. However this doesn't seem to work when it comes to select. The "mousedown-on-selectfield"-animation works but the select is not opening.

我试过了:

<label for="my_id">Click me</label>
<select id="my_id">
  <option>1</option>
  <option>2</option>
</select>

然后:

<label for="my_id">Click me
  <select id="my_id">
    <option>1</option>
    <option>2</option>
  </select>
</label>

知道我做错了什么吗?

PS:Imo 这里不需要任何 Javascript,因为这是一个 html 功能

PS: Imo there should be no need for any Javascript here since this is an html-feature

推荐答案

根据 W3C,单击标签可能什么也不做或将 onFocus 事件发送到相关字段.在这种情况下,通常会在 select 元素上触发 onFocus.

As per W3C, clicking on a label might do nothing or send onFocus event to the related field. In this case, normally it will trigger onFocus on the select element.

这篇关于单击标签不会打开选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆