簡體   English   中英

根據選定的下拉值從文本字段中添加或刪除日期選擇器

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

我有一個用於搜索數據的表格。 在那個表單上,我有一個textbox 、一個dropdown list和一個搜索button 在我的dropdown中,我有選項:

  • 登記日期
  • 預訂編號

我想在textbox添加一個datepicker ,但前提是選擇了“簽入日期”。

datepicker添加到textbox后 - 我無法將其刪除。 選擇其他選項后,如何刪除datepicker

這是我的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.

例子:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM