简体   繁体   English

根据选定的下拉值从文本字段中添加或删除日期选择器

[英]Add or remove a datepicker from a textfield according to selected dropdown value

I have a form used to search data.我有一个用于搜索数据的表格。 On that form I have a textbox , a dropdown list , and a search button .在那个表单上,我有一个textbox 、一个dropdown list和一个搜索button In my dropdown , I have options:在我的dropdown中,我有选项:

  • check in date登记日期
  • last name
  • reservation id预订编号

I want to add a datepicker to the textbox , but only when "check in date" has been selected.我想在textbox添加一个datepicker ,但前提是选择了“签入日期”。

Once the datepicker is added to the textbox - I can't remove it.datepicker添加到textbox后 - 我无法将其删除。 How can I remove the datepicker when the other options have been selected?选择其他选项后,如何删除datepicker

This is my jquery这是我的jquery

$('#list').change(function() {
  var selected = $(this).val();

  if(selected == 2) {
    $('#text').datepicker({ dateFormat: 'yy-mm-dd' });
  } else {
    $('#text').prev().val(''); //here , need to remove the date picker 
  } 
});

Ok when the another option is selected you can use the .datepicker( "destroy" ) function to remove it. Ok when the another option is selected you can use the .datepicker( "destroy" ) function to remove it.

example:例子:

if(selected == 2) {
    $('#text').datepicker({ dateFormat: 'yy-mm-dd' });
  } else {
    $('#text').prev().val('');

    // first test if it exist...example you can set a property then if true destroy it.
    $('#text').datepicker("destroy");
  } 

暂无
暂无

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

相关问题 根据从下拉列表中选择的值显示表单 - Displaying a form according to the selected value from dropdown list 从选定的下拉列表 CodeIgniter 中将数据显示到文本字段 - Display Data to textfield from selected dropdown CodeIgniter 单击添加按钮 php 从第二个下拉列表中删除/禁用所选选项[从第一个下拉列表中选择] - Remove / disable selected option[selected from first dropdown] from second dropdown on clicking add button php 从下拉列表中仅获取选择的值,并从下拉列表中删除未选择的值 - Get only selected value from the dropdown and remove unselected value from the dropdown 使用split()从选择下拉列表中填充文本字段值 - filled textfield value from select dropdown with split() 从下拉菜单中选择统计信息后,使用自定义文本自动填充文本字段 - Autofill textfield with custom text after selected a stat from dropdown menu 显示下拉菜单中的选定值 - show selected value from dropdown 根据数据库中的值自动选择下拉列表 - Select Dropdown Automatically According to value from Database 如何从第一个下拉列表中删除所选值,以便它不会出现在第二个下拉列表中。 (直接来自数据库的值)[Laravel] - How to remove the selected value from first dropdown, so that it wont be in the second dropdown. (value direct from database) [Laravel] 从下拉列表中删除选定的选项 php - Remove selected option from dropdown php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM