当我从外部文件加载内容时,Jquery功能无效。
Index.php
<div id="sub_page" >
</div>
<a href="#" onClick="sub_page(test,"1")"> Load Div</a>
<script type="text/javascript">
function sub_page(con,id) {
$("#sub_page").html('<br><br><img src="/img/custom/loader.gif" /> Please Wait...<br><br> ');
$("#sub_page").load('/function/code.php?con='+ con + "&id=" + id); }
$('#datepicker').datetimepicker({
yearOffset:0,
lang:'en',
timepicker:false,
format:'d/m/Y',
formatDate:'Y/m/d',
minDate:'-2013/01/01', // yesterday is minimum date
maxDate:'+2015/01/01' ,// and tommorow is maximum date calendar
mask:'99/19/3939'
});
</script>
code.php
<input type="text" id="datepicker" value="">
当我尝试从code.php
加载div时,datepicker jquery函数无效。但是,当我尝试将代码粘贴到index.php
本身时,它正在运行。像
工作代码
<div id="sub_page" >
<input type="text" id="datepicker" value="">
</div>
<script type="text/javascript">
$('#datepicker').datetimepicker({
yearOffset:0,
lang:'en',
timepicker:false,
format:'d/m/Y',
formatDate:'Y/m/d',
minDate:'-2013/01/01', // yesterday is minimum date
maxDate:'+2015/01/01' ,// and tommorow is maximum date calendar
mask:'99/19/3939'
});
</script>
所以请帮我纠正这个错误。
答案 0 :(得分:0)
尝试在加载完成后调用datepicker:
$("#sub_page").load('/function/code.php?con='+ con + "&id=" + id, function() {
$('#datepicker').datetimepicker({
yearOffset:0,
lang:'en',
timepicker:false,
format:'d/m/Y',
formatDate:'Y/m/d',
minDate:'-2013/01/01', // yesterday is minimum date
maxDate:'+2015/01/01' ,// and tommorow is maximum date calendar
mask:'99/19/3939'
});
});