2014-12-30 33 views
1

我有這個問題。我正在嘗試創建一個表單頁面,它將使用while循環顯示數據列表,並且每個表單都有輸入字段選項以選擇將全部提交的日期。到目前爲止,我已經顯示了大約4個字段,但datepicker只適用於第一個。其餘的只是空的文本框。在一個while循環中的日期選擇器

這是我的代碼:

$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"/> 

} 

回答

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應該有一個獨特的價值。您不能使用相同的ID datepicker定義4 datepicker。相反,您應該使用屬性class。您的JQuery選擇器變成$('.datepicker')

相關問題