我在这里更新了我的代码:
<div class="selector">
<h2 class="heading">Choose A Date</h2>
</div>
<img class="page-img" src="images/" width ="400px" height="600px" alt="front page here" title="image here">
<script type="text/javascript">
// Datepicker
$(document).ready(function (){$('.selector').datepicker({
inline: true,
dateFormat: 'yy-mm-dd',
constrainInput: true,
changeYear: true,
changeMonth: true,
maxDate: '0',
yearRange: '-100y',
onSelect: function(dateText, inst) {
//$("input[name='yy-mm-dd']").val(dateText);
$(".page-img").attr("images/", dateText + ".jpg");
}
});
});
我需要让日期选择器工作,这样当选择日期时,就会调用一个图像,每个日期都有自己独特的图像。有人建议我使用jQueryattr()方法,并将其用于图像的src。
看看这个,我给你举了一个例子:
http://jsfiddle.net/oscarj24/4xYfp/
希望这能帮助
要实现这一点,以下代码可能会有所帮助:
在日期选择器中,您有一个事件onSelect。当有人选择日期时,您将更改图像。
$('.selector').datepicker({
onSelect: function(dateText, inst) {
alert("Selected date: " + dateText) // For exemple
$("yourImage").attr("src", dateText + ".jpg") // Change the src for the "yourImage".
}
});
然而,你最终会遇到这样的问题,2012-03-08是一个日期,下一个是2012-03-09,所以你可能只想抓住这一天?
参见示例:http://jsbin.com/azunup/4/edit#javascript,html,实时