[英]How to activate jquery function when loading from external file?
Jquery function is not working when i am loading content from external file. 当我从外部文件加载内容时,jQuery函数不起作用。
Index.php 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 code.php
<input type="text" id="datepicker" value="">
When i am trying to load div from code.php
datepicker jquery function is not working. 当我尝试从
code.php
jQuery加载div时无法正常工作。 But when i am trying to paste code to index.php
itself it is working. 但是,当我尝试将代码粘贴到
index.php
本身时,它正在工作。 Like 喜欢
Working Code 工作守则
<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>
So please help me to correct this Error. 因此,请帮助我纠正此错误。
Try to call datepicker once the load is complete : 加载完成后,尝试调用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'
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.