我有一个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