如何让日期选择器出现在 table php 中的每一行
How to make datepicker appear on every row in table php
我在尝试在每个 table 行上显示日期选择器时遇到问题,这些都是文本字段(总共 9 个),日期选择器仅出现在日期列下的第一行,其他 8 个保留作为普通的文本框。对于如何解决此问题,我将不胜感激。这是我的代码:
//日期选择器函数()代码
<script>
$('.datepicker').each(function(){
$(this).datepicker();
});
</script>
//打印日期选择器table行代码。
echo '<td><input type="text" name="datepicker" class="datepicker"></td>';
echo '</tr>';
您不需要 $.each
:
$('.datepicker').datepicker();
我想你缺少的是
$( document ).ready(function() {
//do stuff here
});
也许你的代码在 DOM 完全加载之前触发,特别是如果它被放置在 <head>
部分,并且它只捕获第一个输入。
由于没有更多详细信息,这只是一个猜测。
此外,您应该避免使用服务器端脚本打印静态 HTML 字符串。
我在尝试在每个 table 行上显示日期选择器时遇到问题,这些都是文本字段(总共 9 个),日期选择器仅出现在日期列下的第一行,其他 8 个保留作为普通的文本框。对于如何解决此问题,我将不胜感激。这是我的代码:
//日期选择器函数()代码
<script>
$('.datepicker').each(function(){
$(this).datepicker();
});
</script>
//打印日期选择器table行代码。
echo '<td><input type="text" name="datepicker" class="datepicker"></td>';
echo '</tr>';
您不需要 $.each
:
$('.datepicker').datepicker();
我想你缺少的是
$( document ).ready(function() {
//do stuff here
});
也许你的代码在 DOM 完全加载之前触发,特别是如果它被放置在 <head>
部分,并且它只捕获第一个输入。
由于没有更多详细信息,这只是一个猜测。
此外,您应该避免使用服务器端脚本打印静态 HTML 字符串。