If-else Statement with下拉列表

时间:2018-01-22 04:25:10

标签: html if-statement

我正在进行注册页面。因此,有一个下拉列表,用户可以选择他们是学生,员工还是客人。如果选择学生,则需要输入管理员编号。对于员工,员工ID和客人的身份证。

我可以知道怎么做吗?

enter image description here

1 个答案:

答案 0 :(得分:1)

我认为这可能是您正在寻找的。

请记住,这是在jQuery库的帮助下完成的,因此您需要将其包含在代码中。

此外,为了进一步参考,在发帖时,请务必按照我下面的代码而不是图片来包含您的代码。



$(document).ready(function () {
  $('.group').hide();
  $('#student').show();
  $('#selectMe').change(function () {
    $('.group').hide();
    $('#'+$(this).val()).show();
  })
$("input[placeholder]").each(function () {
        $(this).attr('size', $(this).attr('placeholder').length);
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="selectMe">
  <option value="student">Student</option>
  <option value="staff">Staff</option>
  <option value="guest">Guest</option>
</select>
<div id="student" class="group">
  <input type="text" placeholder="Please enter your Admin Number">
</div>
<div id="staff" class="group">
  <input type="text" placeholder="Please enter your Staff ID">
</div>
<div id="guest" class="group">
  <input type="text" placeholder="Please enter your NRIC">
</div>
&#13;
&#13;
&#13;