我有一個form
多個下拉菜單和一個submit
按鈕。根據從DropDown
所做的任何選擇,我禁用了其他下拉菜單,但是在我點擊提交按鈕後,它會刷新頁面,並且set
禁用下拉菜單爲enabled
。即使刷新頁面後,如何禁用這些下拉菜單。使提交按鈕被擊中後禁用功能持久
下面是我的Script
:
<script>
//Script to disable the dropdown on any selection
var pickId;
$(document).ready(function() {
$('select').change(function() {
$this = $(this);
pickId= $this.attr('id');
pickValue = $this.val();
if (pickId== 'type') {
$('select').prop('disabled', false);
if (pickValue == 'one') {
$('#parts').prop('disabled', true);
} else if (pickValue == 'two') {
$('#country').prop('disabled', true);
} else if (pickValue == 'three') {
$('#parts').prop('disabled', true);
$('#country').prop('disabled', true);
$('#today').prop('disabled', true);
}
}
})
});
</script>
我JSP
頁:
<div id='first'>
<form id='form' method='post' action='/test/'>
<input type="hidden" name="action" value="checker">
<select id="type" name="selectionOne">
<option value="main">selection1</option>
<option value="one">Selection2</option>
<option value="Two">Selection3</option>
<option value="Three">Selection3</option>
</select>
<% // tried to do in JSP but did not work???
String typeChker = request.getParameter("selectionOne");
%>
<script> // tried to do in JSP but did not work???
document.getElementById("type").value = '<% out.print(typeChker); %>';
</script>
<select id="Parts" name="partially">
<option value="1">1</option>
<option value="12">12</option>
</select>
<%
String dur = request.getParameter("partially");
%>
<script>
document.getElementById("Parts").value = '<% out.print(dur); %>';
var e = document.getElementById("Parts");
var strUser = e.options[e.selectedIndex].text;
</script>
<select id="country" name="ally">
<option value="6">USA</option>
<option value="9">UK</option>
</select>
<select id="today" name="aty">
<option value="123">Today</option>
<option value="6">tomorrow</option>
</select>
<input type="Submit" Value="Submit">
</form></div>
一個提交按鈕後擊中,它調用servlet來提供基於這些選擇的響應,從而刷新了整個test.jsp
如何使禁用值持久 ,直到用戶不單獨更改選項。
請糾正我,如果我對任何錯誤和我需要添加它有持久性。
謝謝developerwjk,所以目前我在我的JSP文件都被processign響應一個Servlet會從被張貼在發送請求請給我舉個例子或鏈接,通過這些例子或鏈接我可以學習如何進行會話nd同樣繼續,因爲我是JSP新手,所以試圖把所有的東西都粘在一起。 – AKIWEB
會話就像使用session.setAttribute(name,value)一樣簡單,並檢索session.getAttribute(name);當檢索時,它會返回一個Object,所以你必須進行類型轉換:boolean x =(boolean)session.getAttribute(name);例如。 – developerwjk
謝謝developerwjk,我確實遵循了一些簡單的例子,它們讓我可以將任何表單元素的值保存到'session變量'中。但在我的情況下,該特定的下拉值或文本的值是持久的,但不是JQuery腳本部分。您如何通過使用'session'來指導實現這一點? – AKIWEB