वर्तमान में, डेटपिकर प्रति पृष्ठ केवल 1 तत्व बनाता है कि सभी 'डेटपिकर' इनपुट साझा करते हैं, इसलिए लिंक किए गए प्रश्न का उत्तर क्यों काम नहीं करता है। पहले शो घटना .addClass() या .css() के साथ डेटपिकर तत्व को संपादित करने की अनुमति नहीं देती है (क्योंकि तत्व संरचना को जब यह दिखाता है तो डेटपिकर स्क्रिप्ट से रीफ्रेश किया जाता है।)
इस पर जाने के लिए, मैंने पाया कि फोकस इनपुट तत्व के लिए ईवेंट डेटपिकर दिखाए जाने के बाद कोड चलाने के लिए प्रतीत होता है। यह एक निराशाजनक समस्या के लिए एक सरल कामकाज है।
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<script type="text/javascript">
$(function() {
$('.month-picker').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
},
beforeShow : function(input, inst) {
if ((datestr = $(this).val()).length > 0) {
year = datestr.substring(datestr.length-4, datestr.length);
month = jQuery.inArray(datestr.substring(0, datestr.length-5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
$(this).datepicker('setDate', new Date(year, month, 1));
}
}
});
$('.date-picker').datepicker();
$('.month-picker').focus(function() {
$('.ui-datepicker-calendar').addClass('hideDates');
});
});
</script>
<style>
.hideDates {
display: none;
}
</style>
</head>
<body>
<label for="startDate">Date:</label>
<input name="startDate" id="startDate" class="date-picker" />
<label for="endMonth">End Month:</label>
<input name="endMonth" id="endMonth" class="month-picker" />
</body>
</html>
स्रोत
2010-11-17 15:27:22
हाय आपके तरह के उत्तर के लिए धन्यवाद, इसके बारे में और जानकारी दे सकते हैं, ठीक है, मैं jquery.ui.datetimepicker.js से एक और .js फ़ाइल कॉल monthpicker.js को डुप्लिकेट करता हूं, तो अगला कदम यह आपके द्वारा समझाया जाना चाहिए " सीएसएस चयनकर्ताओं और सीएसएस फ़ाइल "? – Darren
@ डैरेन - आपको कोड को चुनने की आवश्यकता है और देखें कि स्क्रिप्ट उन वस्तुओं को चयनकर्ताओं/आईडी को कैसे निर्दिष्ट कर रही है जो इसे बनाता है और उन्हें 'डेटपिकर' के बजाय 'monthpicker' का उपयोग करने के लिए बदलता है। फिर आपको सीएसएस फ़ाइल की प्रतिलिपि बनाने और वहां मिलान करने वाले बदलाव करने की आवश्यकता है। – Paddy
ठीक है, बस आश्चर्य कीजिए कि क्या मैं कक्षा .ui-datepicker-calendar का चयन करने के लिए सीएसएस विरासत का उपयोग कर सकता हूं जो <इनपुट प्रकार = "टेक्स्ट" id = "monthPicker" /> में मेरे एकमात्र डेटपिकर से संबंधित है? – Darren