我在datepicker上有一个奇怪的问题,我无法从FIREFOX中选择日期,而是接受日期(手动输入)作为进程的输入。
我正在使用Jquery日期选择器USING jquery version v1.11.2
$(document).ready(function() {
var time_value = '01.12.2000';
var values = time_value.split(".");
var parsed_date = new Date(values[2], values[1], values[0]);
$("#todate").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: "-150:c",
minDate: parsed_date,
maxDate: "+0d"
});
var todate = '<?=str_replace('-', '/',$totimestamp);?>'
if (todate != 'NULL') {
$("#todate").datepicker("setDate", todate);
}
$("#fromdate").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: "-150:c",
minDate: parsed_date,
maxDate: "+0d"
});
var fromdate = '<?= str_replace('-', '/',$fromtimestamp);?>';
if (fromdate != 'NULL') {
$("#fromdate").datepicker("setDate", fromdate);
}
});
这适用于chrome和其他浏览器(我可以从日期选择器中选择),但在Firefox中它不起作用。
我独立尝试了样品,效果很好。
答案 0 :(得分:1)
我不确定您的代码是否也适用于任何其他浏览器。我看到语法错误SyntaxError: missing } after function body
您需要关闭文档ready.try this:
$(document).ready(function() {
var time_value = '01.12.2000';
var values = time_value.split(".");
var parsed_date = new Date(values[2], values[1], values[0]);
$( "#todate" ).datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true,changeYear: true,yearRange:"-150:c",minDate:parsed_date,maxDate: "+0d"});
var todate="<?=str_replace('-', '/',$totimestamp);?>";
if (todate != 'NULL') {
$("#todate").datepicker("setDate",todate);
}
$( "#fromdate" ).datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true,changeYear: true,yearRange:"-150:c",minDate:parsed_date,maxDate: "+0d"});
var fromdate="<?= str_replace('-', '/',$fromtimestamp);?>";
if (fromdate!= 'NULL') {
$("#fromdate").datepicker("setDate",fromdate);
}
});
&#13;
<link href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<input type="text" id="fromdate"/> <input type="text" id="todate"/>
&#13;
Or Try setting z-index of input to something like 10000 and see
答案 1 :(得分:1)
此代码适用于IE,Firefox和资源管理器
<html>
<body>
<div>
FromDate: <input type="text" id="fromdate" class="datepicker"/>
ToDate: <input type="text" id="todate" class="datepicker"/>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script>
$(document).ready(function() {
var time_value = '01.12.2000';
var values = time_value.split(".");
var parsed_date = new Date(values[2], values[1], values[0]);
$("#todate").datepicker({dateFormat: 'dd/mm/yy',changeMonth: true,changeYear: true,yearRange:"-150:c",minDate:parsed_date,maxDate: "+0d"});
var todate="<?=str_replace('-', '/','19-11-2015');?>"
if (todate != 'NULL') {
$("#todate").datepicker("setDate",todate);
}
$( "#fromdate" ).datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange:"-150:c",minDate:parsed_date,maxDate: "+0d"});
var fromdate="<?= str_replace('-', '/','21-11-2015');?>"
if (fromdate!= 'NULL') {
$("#fromdate").datepicker("setDate",fromdate);
}
});
</script>
</body>
这是jsfiddle的链接
https://jsfiddle.net/tz3qLaa8/
请注意代码
var todate = '<?=str_replace('-', '/',$totimestamp);?>'
错了。你需要在openinig上使用双引号并关闭字符串,因为你在字符串
中使用单引号