在单选按钮的标签内输入文本输入? [英] Put text input inside label for radio button?

查看:144
本文介绍了在单选按钮的标签内输入文本输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使一个收音机组指定一堆选项,和一个额外的选项其他与文本输入要指定。我使用的特定单选按钮的代码是

I'm trying to make a radio group specifying a bunch of options, and an extra option "other" with a text input to specify. The code for this particular radio button I'm using is

<input type='radio' name='RadioInput' value='Other' id='RadioInput_Other' />
  <label for='RadioInput_Other'>Ohter: 
  <input type='text' name='RadioInput_Other_Value' id='RadioInput_Other_Value' value='' />
  </label>

这个想法是,如果您将焦点放在文本输入上,则选择与其对应的单选按钮。上面的代码几乎这样做(因为文本输入在标签内)。但是,它也将焦点移动到单选按钮(这是恼人的,因为任何你下一个类型丢失)。

The idea is that if you give focus to the text input, the radio button corresponding to it is selected. The code above almost does this (since the text input is inside the label). However, it also shifts focus to the radio button (which is annoying, since whatever you type next is lost).

有任何方法来防止这种使用XHTML1.0 / CSS2?

Is there any way to prevent this using XHTML1.0 / CSS2? Preferably without using javascript.

推荐答案

将控件放置在标签中将该标签与该控件相关联,您只能有一个控件与给定标签相关联。因此,这是不一致的HTML。

Placing a control inside a label associates that label with that control, and you may only have one control associated with a given label. This is therefore non-conformant HTML.

JavaScript是更好的选择。

JavaScript is the better option here.

这篇关于在单选按钮的标签内输入文本输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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