
jsp下拉框主要使用select和option标签进行创建,如下代码:
<html><body>
<span style="absolutemargin-top:-12px">
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td align="left"><!-- 创建一个下拉框-->
<span style="position:absoluteborder:1pt solid #c1c1c1overflow:hiddenwidth:188pxheight:19pxclip:rect(-1px 190px 190px 170px)">
<select name="aabb" id="aabb" style="width:190pxheight:20pxmargin:-2px" onChange="changeF()">
<option value="" style="color:#c2c2c2">---请选择---</option>
<option value="闲人书库">闲人书库</option>
<option value="闲人BLOG">闲人BLOG</option>
<option value="<a href="http://www.ayinsky.com" target="_blank">闲人设计</a>"><a href="http://www.ayinsky.com" target="_blank">闲人设计</a></option>
<option value="闲人软件">闲人软件</option>
</select>
</span>
<span style="position:absoluteborder-top:1pt solid #c1c1c1border-left:1pt solid #c1c1c1border-bottom:1pt solid #c1c1c1width:170pxheight:19px">
<input type="text" name="ccdd" id="ccdd" value="可选择也可输入的下拉框" style="width:170pxheight:15pxborder:0pt">
</span>
</td>
</tr>
</table>
</span>
</body>
<script language="javascript">
function changeF()
{
// 从下面的赋值可以的值,你在action 中只要得到name =“ccdd” 的值就可以了。
document.getElementById('ccdd').value=document.getElementById('aabb').options[document.getElementById('aabb').selectedIndex].value
}
</script>
</html>
用jsp做树形下拉框可以用java自定义标签实现。
参考代码如下:
package com.moonNigh.tagSupportimport java.io.IOException
import javax.servlet.http.HttpServletRequest
import javax.servlet.jsp.JspException
import javax.servlet.jsp.JspWriter
import javax.servlet.jsp.tagext.TagSupport
/**
*
*
* 树形下拉选择控件
*
*/
public class SelectorTag extends TagSupport {
private static final long serialVersionUID = 9878861374414215L
//标签name属性
private String name
//所需图片的路径
private String imgPath
//所需javascript文件的路径
private String scriptPaht
//所需css文件的路径
private String cssPath
//项目的根路径
private String rootPath
//标签的value属性
private String value
private String text
private String path
/*
* 标签的actionUrl属性
* 联想查询结果数据通过向actionUrl属性指定的url请求得到
*/
private String actionUrl
private HttpServletRequest request=null
public String getActionUrl() {
return actionUrl
}
public void setActionUrl(String actionUrl) {
this.actionUrl = actionUrl
}
public String getValue() {
return value
}
public void setValue(String value) {
this.value = value
}
public String getImgPath() {
return imgPath
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath
}
public String getScriptPaht() {
return scriptPaht
}
public void setScriptPaht(String scriptPaht) {
this.scriptPaht = scriptPaht
}
public String getCssPath() {
return cssPath
}
public void setCssPath(String cssPath) {
this.cssPath = cssPath
}
public String getText() {
return text
}
public void setText(String text) {
this.text = text
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public SelectorTag()
{
}
/**
* 初始化变量
*/
private void initAbttributes()
{
request=(HttpServletRequest)this.pageContext.getRequest()
rootPath=request.getContextPath()
this.imgPath="/images/"
this.scriptPaht="/js/"
this.cssPath="/css/"
}
@Override
public int doStartTag() throws JspException {
initAbttributes()
path=rootPath+"/jsp/tags/treeSelectorPage.jsp?id="+id+"&actionUrl="+actionUrl
JspWriter out=pageContext.getOut()
try {
String tName=name
//引入javascript文件
out.println("<script type='text/javascript' charset='GB2312' src='"+rootPath+scriptPaht+"selector.js'></script>")
//引入css文件
out.println("<link rel='stylesheet' href='"+rootPath+cssPath+"selector.css' type='text/css' />")
StringBuilder tag=new StringBuilder("<input type='text' ")
tag.append("id='").append(id).append("'")
tag.append(" value='").append(text==null?"":text).append("'")
tag.append(" onclick='return showSelector(\"")
tag.append(id).append("\",\"").append(path).append("\")' readonly>")
tag.append("<input type='hidden' name='")
.append(tName).append("' id='").append(id).append("_value")
.append("' value='").append(value==null?"":value).append("'>")
out.println(tag.toString())
} catch (IOException e) {
e.printStackTrace()
}
return SKIP_BODY
}
}
运行结果:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)