选择选项可打开唯一的文本框

时间:2013-01-24 04:39:43

标签: html forms select textbox

我希望有两个不同的选择选项,例如EMAIL或PHONE NUMBER等选项,当您选择EMAIL选项时,会在其下方打开一个文本框,显示“输入电子邮件”或选择电话号码时选项后面会打开一个不同的文本框,显示“输入电话号码:”。

聚苯乙烯。我不希望同时显示两个文本框,我希望他们选择要填写的文本框。如果您有更好的方法,请告诉我您的想法。

<form action="order-step4.php" method="post"> 

    Please fill out these fields:<br /> 
    Recipient: <input type="text" name="recipient" /><br />

    Recipient Email: <input type="text" name="remail" /><br /> 

    Recipient Cell: <input type="text" name="rsms" /><br /> 

    Your Message :<input type="text" name="message" /><br /> 

    <input type="submit"> 
 </form>

谢谢你, 乍得。

1 个答案:

答案 0 :(得分:0)

有一个用于选择手机或电子邮件的下拉选项,并在下拉列表更改时显示/隐藏相应的输入文本框。

<select id="myChoice">
  <option value="email">Email</option>
  <option value="phone">Phone</option>
</select>

这是功能

$('#myChoice').change(function() {
       if ($(this).val() === 'email') {
           //show email
           //hide phone

        } else {
            //hide email
           //show phone
        }
});