为了账号安全,请及时绑定邮箱和手机立即绑定

单击一个特定的单选按钮/选择选项后添加一个文本字段

单击一个特定的单选按钮/选择选项后添加一个文本字段

PHP
翻过高山走不出你 2021-06-11 14:08:46
单击一个特定的单选按钮或选择选项后,我想添加一个文本输入我有一个表单,其中有两个部分,其中单击“Sonstiges”(德语为“其他”)应该显示或添加附加文本输入,用户可以在其中为自己添加一些内容我找不到解决方案。我能找到的唯一方法是通过 ajax 添加动态输入量。但为此,我只需要一个固定数量。所以我想知道是否有更简单或更优雅的方法。应该发生的地方<h2>Problem & Geräteauswahl</h2>        <?php            //Einbinden der Datenbankverbindung            include 'dbconfig.php';            //Auslesen aller Gerätetypen            $query = $db->query("SELECT * FROM typ ORDER BY name ASC");            //Auslesen der Zeilen            $rowCount = $query->num_rows;        ?>              <label for='gtyp'> Gerätetyp:            <select name = 'gtyp' id = 'gtyp'>            <option>Bitte Auswählen</option>        <?php            if($rowCount > 0){                while($row =  $query->fetch_assoc()){                    echo '<option value="'.$row['typ_ID'].'">'.$row['name'].'</option>';                }            } else{                echo '<option>Wenn sie das sehen, hat Chris seinen Job nicht gut gemacht</option>';            }            ?>            <option>Sonstiges</option>            </select>            </label>        <br>            <label for = 'hers'> Hersteller:            <select name = 'hers' id= 'hersteller'>                <option>Bitte Gerätetyp wählen</option>            </select>            </label>        <br>            <label for = 'ger'> Gerätebezeichnung:            <select name = 'ger' id= 'geraet'>                <option>Bitte Hersteller wählen</option>            </select>            </label>        <br>        Add Testfield here        <br>
查看完整描述

1 回答

?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

您可以在您的选择下添加:


<input type="text" id="sonstiges" hidden>

并在您的脚本中:


$('#gtyp').change(function(){

  var optionSelected = $('#gtyp option').filter(':selected').text();

  if(optionSelected == "Sonstiges"){

    $('#sonstiges').toggle();

  }

});


查看完整回答
反对 回复 2021-06-13
  • 1 回答
  • 0 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号