
<div id="sel" style="display: none">
<select name="select2">
<option value="1" selected>采购部</option>
<option value="2">生产部</option>
<option value="3">库存部</option>
</select>
</div>
<div id="in" style="display: none">
<input type="text" name="userInfo" class="logininput" id="name" size="25">
</div>
<select name="select" onchange=myselect()>
<option value="department" selected>用户部门</option>
<option value="userName">用户姓名</option>
</select>
在JavaScript块里定义这个函数:
function myselect(){
//selectedIndex == 0 表示选了:用户部门
if(documentforms[form1]select[0]selectedIndex == 0){
documentgetElementById('sel')styledisplay = "";
documentgetElementById('in')styledisplay = "none";
return;
}
//selectedIndex == 0 表示选了:用户姓名
if(documentforms[form1]select[0]selectedIndex == 1){
documentgetElementById('in')styledisplay = "";
documentgetElementById('sel')styledisplay = "none";
return;
}
}
这样应该就可以了,是手写的,不知道有没有拼错,楼主有问题可以M我!!
获取当前的然后做比较,windowlocationhref是获取不到的,需要嵌入java代码,通过request来获取:
String url=requestgetScheme()+"://";url+=requestgetHeader("host");
url+=requestgetRequestURI();
if(requestgetQueryString()!=null)
url+=""+requestgetQueryString();
然后做比较
以点到面,知道了web中getContextPath()这种获取路径的方式,显然其他的方式的是可以以此类推的。常说,工作学习找共同点嘛。 上一段我们也提高getContextPath()的含义,是jsp中获取路径的一种方式,返回当前页面所在的应用的名字。知其然知其所以然,知道它大体上的含义,看看在项目中是如何使用的
String path = requestgetContextPath();
String basePath = requestgetScheme()+"://"+requestgetServerName()+":"+requestgetServerPort()+path+"/";">
在程序中我们一般这样使用。说到了这里,我们可以看看request常用的方法:
requestgetSchema(),返回的是当前连接使用的协议,一般应用返回的是>
你好!
用js就可以实现呀
每一个控件可以加一个id的属性,然后写JS
documentgetelementById("elementname")value
就可以了
如果对你有帮助,望采纳。
如果通过前台控制实现也是可以的就是判断当前时间然后给与链接,但是这样只是获取了当前本地的时间,别人改了时间也是一样可以访问的。
建议通过ajax实现,当点击的时候去后台判断是否是可以访问的时间,然后才给与链接。
//由于我采用的是jquery下的ajax所以要引入jquery
<script src="<%=basePath%>js/jquery-172js"></script>
<script type="text/javascript">
$(fcuntion(){
//为绑定onclick单击事件(每点击一次去服务器判断是否是可访问的时间)
$('#id')bind("click",function(){
$ajax({
type: "POST",
url: '这里写链接到后台的URL(在服务器判断访问的时间,可访问时返回“true”)',
dataType: 'text',
success: function(data) {
if("true" == data){
//如果后台返回的是true
locationhref="这里是你要跳转的链接URL";
} else {
//后台返回false就执行该 *** 作
alert('暂未开放!');
}
}
});
});
});
</script>
你得先选中其中一个
在提交到servlet,没有提交你肯定获取空值,string
em_typework=requestgetparameter("em_typework");建议你在servlet里打印下这个字符串,你要先判断你获取的这个字符串是不是空值,这么取值是对的,不可能取不到,你是直接提交到这个页面的吗,你不能提交到别的servlet在到取值的这个servlet,因为下拉框的这个值是放在request的作用域里的
javascript中获取jsp界面元素方法
1getElementsByName("name")
可以获取jsp界面中元素名字为"name"的所有元素,返回的是一个object[ ] 数组,数组中每个元素包含一个从jsp界面中获得的元素。
2getElementById(id)
根据id值来获取jsp界面中惟一的对象。
servlet中获取jsp界面元素方法
3getParameter("name") 返回类型为String
用于获取jsp界面中一个名字为"name"的对象的value值。
4getParameterValues("name")返回类型为String[]
用于获取jsp界面中多个名字为"name"的对象的value值。
以上就是关于JSP怎样获取当前页select值并作为后面判断条件全部的内容,包括:JSP怎样获取当前页select值并作为后面判断条件、jsp页面如何判断当前地址是否正确、web项目中,request的方法详解等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)