这是我的按钮
<div class="block">
<?=form_line(lang('start_date'),form_input('start_date', date('Y-m-d')))?>
<a id="Add">Click to add textbox</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('input[name=start_date]').datepicker({maxDate: constants.MAX_YEAR+'-12-31', changeYear: true, changeMonth: true, dateFormat:'yy-mm-dd'});
$('input[name=end_date]').datepicker({maxDate: constants.MAX_YEAR+'-12-31', changeYear: true, changeMonth: true, dateFormat:'yy-mm-dd'});
$("#Add").on("click", function() {
var row = '<?=form_line(lang('start_date'),form_input('start_date', date('Y-m-d')))?>';
$('block').append(row)
});
}) // eof ready
</script>
我如何附加form_line(lang('start_date'),form_input('start_date', date('Y-m-d')))?>
同时点击链接“单击以添加文本框”
答案 0 :(得分:1)
对动态添加的元素执行类似的操作
$('body').on('focus',".datepick", function(){
$(this).datepicker({
maxDate: constants.MAX_YEAR+'-12-31',
changeYear: true,
changeMonth: true,
dateFormat:'yy-mm-dd'
});
});
只需将类datepick
添加到您的表单输入中即可:
$(document).ready(function() {
$("#Add").on("click", function() {
var row = '<?=form_line(lang('start_date'),form_input('start_date', date('Y-m-d'),'class="datepick"'))?>';
$('block').append(row)
});
});