2017-09-15 32 views
2

我正在为我的业务做一个网站,在这种形式下,我想让他们选择他们的设备出了什么问题。如果他们的问题不在列表中,我希望他们将其输入<textarea>。我想知道是否可以将该文本区域作为我的单选按钮选项之一。到目前为止,我有这个...想知道如果我可以嵌套输入类型

<fieldset> 
 
    <legend> What's wrong with your device </legend> 
 

 
    <label> <input type = "radio" name = "problem"> 
 
    \t \t \t \t \t Cracked Screen </label> 
 

 
    <label> <input type = "radio" name = "problem"> 
 
    \t \t \t \t \t Broken Camera </label> 
 

 
    <label> <input type = "radio" name = "problem"> \t \t \t \t 
 
    \t \t \t <textarea rows = "4" cols = "15" name = "problem" 
 
         placeholder = "other problems"></textarea>    
 
         </label> 
 

 

 
</fieldset>

这似乎是它的工作,但我担心,它只是呈现文本区域视为同一标签下自己的输入。有什么建议?

另外我想知道如何让我的单选按钮能够被点击。你只能激活它们,但是你不能停用它们。这只能用JavaScript来完成吗?

+0

的可能的复制[您如何克服HTML表单嵌套限制?(https://stackoverflow.com/questions/597596/how-do-你-克服最HTML形式的嵌套-限制) –

回答

2

HTML input是一个“空”元素 - 它没有结束标记,也不能包含任何子元素。

你当然可以让它看起来看起来像你的textarea是单选按钮控件的一部分,就像你做的那样,但它不会像没有Javascript一样表现。

第二个问题:用户通常没有办法取消单选按钮。您可以通过编程(例如,点击按钮)或者有另一个“无”选项让他们点击。

0

您不能嵌套输入。可能最好做的是添加JavaScript,在选择其他选项时显示输入文本字段。

0

嵌套元素不可能

按照这个来实现你想要的。

最初隐藏textarea元素。 根据您选择的单选按钮切换textarea可见性。

<fieldset> 
    <legend> What's wrong with your device </legend> 
    <label> <input type = "radio" name = "problem"/>Cracked Screen </label> 
    <label> <input type = "radio" name = "problem"/>Broken Camera </label> 
    <label> <input type = "radio" name = "problem" class="t_txt"/> </label> 
    <textarea class="p_txt" style="display:none" rows = "4" cols = "15" name = "problem" placeholder = "other problems"></textarea> 

</fieldset> 

jQuery的

$("input:radio.t_txt").click(function(){ 
$("textarea.p_txt").toggle(); 
}); 
相关问题