简体   繁体   English

仅在选择特定值时显示文本字段

[英]Displaying a text field only if a particular value is selected

I've created a dropdown list that contains 3 values:我创建了一个包含 3 个值的下拉列表:

  • date wise日期明智
  • active students活跃的学生
  • inactive student不活跃的学生

How can I select a text field asking what the date of birth of the user is, if and only if the person has selected the "date" field?当且仅当该人选择了“日期”字段时,我如何 select 一个文本字段询问用户的出生日期是什么?

Please provide us with more information, and take a look at the jquery ui datepicker.请向我们提供更多信息,并查看 jquery ui 日期选择器。

http://jqueryui.com/demos/datepicker/ http://jqueryui.com/demos/datepicker/

This might be what you're looking for:这可能是您正在寻找的:

http://api.jquery.com/change/ http://api.jquery.com/change/

http://api.jquery.com/show/ http://api.jquery.com/show/

http://api.jquery.com/hide/ http://api.jquery.com/hide/

If you're not familiar with jquery, just take a closer look at the examples on those pages and you should be good to go:)如果您不熟悉 jquery,只需仔细查看这些页面上的示例,您应该对 go 很好:)

//edit - example: //编辑 - 示例:

  <select id="filter_selection">
    <option value="date_wise">Date Wise</option>
    <option value="active_students">Active Students</option>
    <option value="inactive_students">Inactive Students</option>
  </select>

<span id="text" style="display: none"><input type="text" name="text"></span>

<script>
$('#filter_selection').change(function() {
  if($(this).val == 'date_wise') {
    $('#text').show();
  } else { 
    $('#text').hide(); 
  }
});
</script>

...untested;) ...未经测试;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM