jQuery UI Datepicker only respond to the first textbox

僤鯓⒐⒋嵵緔 提交于 2019-12-31 07:22:07

问题


I'm trying to create a table with multiple rows and each row has a text box for user to input the date using the jQuery UI Datepicker. The problem is that the Datepicker is only updating the text box in the first row. Here is the datepicker function in the <head>:

<script>
$(function() {
    $('.dateinput').datepicker({ dateFormat: 'dd/mm/yy' }).val();
});
</script>

This is the text box:

<?php
while($fetch = mysql_fetch_array($query))
{
    echo "<td> <input type='text' id='dateinput' name='dateinput[]' value='" .date('d/m/Y'). "' class='dateinput' /> </td>";
}
?>

Any help would be very much appreciated. :)


回答1:


You are getting this problem as all rows have

id='dateinput'

You need to give them different id. Keep a counter variable and append it to id. Increase it in loop after appending.

Hope this helps.




回答2:


You have problem due to Same Id which conflict You can use same class name

class='dateinput'

It work's



来源:https://stackoverflow.com/questions/20535004/jquery-ui-datepicker-only-respond-to-the-first-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!