0
我是新來的網頁開發和學習最多的「我走」。我在服務器端使用Spring-MVC,在客戶端使用JSP,JQuery和CSS。到目前爲止,我有一個簡單的頁面,其中包含2個時間選擇器(jQuery)和一個列表<div>s
,每個包含項目數據和一個複選框。當點擊提交按鈕時,整個數據都以表格形式提交,並在我的Controller
中收到@RequestParam-s
。在我的下一步中,我希望每個<div>
都具有一個複選框的功能:我實現了一個toggle
函數,該函數更改背景並收集相關ID。現在我的問題是如何將這些數據提交給服務器(時間選擇器和數組ID)?我需要建立一個JSON
對象並提交它嗎?我可以舉例說明如何從toggle
函數中檢索var數組數據,並從input element
獲取時間?
這裏是我的HTML片段:如何從JSP函數提交輸入元素和Ids數組中的數據?
<div class="container" >
<label class="TimeLabel" >Start:</label>
<input type="text" style="width: 3em;" id="timepicker_start" name="timepicker_start" value="09:00" />
<label class="TimeLabel">End:</label>
<input type="text" style="width: 3em;" id="timepicker_end" name="timepicker_end" value="18:00" />
<div/>
...
<!-- item only list -->
<div class="container">
<ul class="plainList">
<c:forEach items="${itemsFrom.itemsOnly}" var="item" varStatus="status">
<li>
<div class="inner">
<img src="resources/images/${item.id}.png">
<ul class="plainList">
<li><h4>${item.title} ™</h4></li>
<li><h5>${item.description}</h5></li>
</ul>
<div style="clear: both"></div>
</div>
</li>
</c:forEach>
</ul>
</div>
和我的功能:
<script type="text/javascript">
var count = 0;
var attrIds = new Array();
$(function() {
$(".inner").toggle(function() {
$(this).css("background", "#2E8B57");
attrIds.push(this.id);
count++;
$("section").find("#attrCount").text(count);
}, function() {
$(this).css("background", "#dcdcdc");
attrIds.splice($.inArray(this.id, attrIds),1);
count--;
$("section").find("#attrCount").text(count);
});
});
</script>