[英]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.