【问题标题】:Datepicker in a while loop循环中的日期选择器
【发布时间】:2014-12-30 13:14:51
【问题描述】:

我有这个问题。我正在尝试创建一个表单页面,它将使用 while 循环显示数据列表,并且每个页面都有输入字段选项来选择将全部提交的日期。到目前为止,我显示了大约 4 个字段,但日期选择器仅适用于第一个字段。其余的只是空文本框。

这是我的代码:

$query = "SELECT * FROM application WHERE Shortlist_status = 1 ORDER BY Candidate_id ASC";
$result = mysqli_query($link, $query) or die(mysqli_error($link));

<html>
<head>

    <link href="stylesheet/style.css" rel="stylesheet"/>
    <script src="script/jquery-1.10.2.min.js"></script>
    <script src="script/jquery-ui-1.10.3.custom.min.js"></script>
    <link rel="stylesheet" href="stylesheet/jquery-ui-1.10.3.custom.min.css">


     <script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>   


</head>
    <title>
        Arrange interview
    </title>

<body>

while ($row = mysqli_fetch_array($result)) {

(Some other input data)

<input type="text" id="datepicker" name="date"/>

}

【问题讨论】:

    标签: php html datepicker


    【解决方案1】:

    使用 datepicker 类而不是唯一 id:

    $query = "SELECT * FROM application WHERE Shortlist_status = 1 ORDER BY Candidate_id ASC";
    $result = mysqli_query($link, $query) or die(mysqli_error($link));
    
    <html>
    <head>
    
        <link href="stylesheet/style.css" rel="stylesheet"/>
        <script src="script/jquery-1.10.2.min.js"></script>
        <script src="script/jquery-ui-1.10.3.custom.min.js"></script>
        <link rel="stylesheet" href="stylesheet/jquery-ui-1.10.3.custom.min.css">
    
    
         <script>
    $(function() {
    $( ".datepicker" ).datepicker(); // Change this line
    });
    </script>   
    
    
    </head>
        <title>
            Arrange interview
        </title>
    
    <body>
    
    while ($row = mysqli_fetch_array($result)) {
    
    (Some other input data)
    
    <input type="text" class="datepicker" name="date"/> // Change this line
    
    }
    

    说明:

    属性id 应该具有唯一值。您不能定义 4 个具有相同 ID datepicker 的日期选择器。相反,您应该使用属性class。您的 JQuery 选择器将变为 $('.datepicker')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 2014-04-22
      相关资源
      最近更新 更多