在這種情況下,我必須將返回的數組列表中的日期賦給文本框。 arraylist是在腳本內部返回的,即對servlet的jquery ajax調用,也是json格式。 數據[0] .demo_planned_on是返回的日期,格式不符合要求。 如何使用這個特定的對象,並將其轉換爲所需的格式 (yyyy-dd-mm)並將其分配給文本框,在ajax腳本本身內。如何將腳本自身轉換爲所需的格式,其中接收傳遞的數據。如何轉換爲jquery ajax腳本中所需的日期格式
servlet的一面:
CustDAO cusName=new CustDAO();
ArrayList<Cust> list2=cusName.dispCustomer2(abcd);
new Gson().toJson(list2, response.getWriter());
jsp頁面:
-------------
-------------
<tr><td>
demo planned on :</td>
<td><input type="text" id="dpo" name="dpo" ></td></tr>
</table>
<script>
$(document).ready(function(){
var selected;
$('#selectUsers').change(function(){
selected = $('#selectUsers').val();
$.ajax({
url: "Servlet2",
type: "Post",
data: {"selectUsers":selected},
dataType: "json",
success : function(data)
{
$('#dpo').val(data[0].demo_planned_on); //getting wrong format here, during assignment of value to textbox with id="dpo". Need (yyyy-mm-dd) format. How to convert here itself??
}
});
});
</script>
以哪種方式,你收到的日期? – cralfaro
我在jsp頁面中獲取日期的格式是(月份日期,年份) – aswathy