[英]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
中,我有选项:
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.