一个小功能

虽不简单 2011-11-14 10:59:00
我用$TagUtil.options($list,"id","proname",$!extends) 取得了一些值(名称)(在下拉列表里显示),与此对应的有一些编号如123等等,我想在网页也上选择名称后直接显示对应的编号。咋办呢?
...全文
165 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
虽不简单 2011-11-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 dulongfie 的回复:]
简单的三级联动代码:当然,数据你可以从后台取值出来,我这里就写死了的

JScript code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>_select</title>

<meta http-equiv="prag……
[/Quote]我大体上有点思路了,谢谢诶! 我做出来 给大家分阿!
roffer 2011-11-18
  • 打赏
  • 举报
回复
简单的三级联动代码:当然,数据你可以从后台取值出来,我这里就写死了的

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>_select</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
var _sf = [{id:'1',value:'四川'},{id:'2',value:'云南'}];
var _ct = [{id:'1_1',pid:'1',value:'成都'},{id:'1_2',pid:'1',value:'内江'},{id:'2_1',pid:'2',value:'文山'},{id:'2_2',pid:'2',value:'昆明'}];
var _ar = [{id:'1_1_1',pid:'1_1',value:'武侯区'},{id:'1_1_2',pid:'1_1',value:'青羊区'},{id:'1_2_1',pid:'1_2',value:'内江一区'},{id:'1_2_2',pid:'1_2',value:'内江二区'},{id:'2_1_1',pid:'2_1',value:'文山一区'},{id:'2_1_2',pid:'2_1',value:'文山二区'},{id:'2_2_1',pid:'2_2',value:'昆明一区'},{id:'2_2_2',pid:'2_2',value:'昆明二区'}];
window.onload = function(){
document.getElementById('sf').options[0] = new Option('请选择','');
for(var i=0;i<_sf.length;i++){
document.getElementById('sf').options[i+1] = new Option(_sf[i].value,_sf[i].id);
}
document.getElementById('sf').onchange = function(){
var value = document.getElementById('sf').value;
if(value!="")getData(document.getElementById('ct'),_ct,value);
};
document.getElementById('ct').onchange = function(){
var value = document.getElementById('ct').value;
if(value!="")getData(document.getElementById('ar'),_ar,value);
};
}
function getData(id,arr,value){
//for(var i=0;i<id.options.length;i++)id.options.remove(i);
id.options.length = 0;
id.options[0] = new Option('请选择','');
for(var i = 0 ;i<arr.length;i++){
if(value==arr[i].pid)id.options[i+1] = new Option(arr[i].value,arr[i].id);
}
}
</script>
</head>
<body>
省份:<select id='sf'></select>
城市:<select id='ct'></select>
区域:<select id='ar'></select>
</body>
</html>

虽不简单 2011-11-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 chabale 的回复:]
ajax省市联动啊
代码:根据你的需求自己改改:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getSer……
[/Quote]


谢谢 我看看可以么!
chabale 2011-11-17
  • 打赏
  • 举报
回复
ajax省市联动啊
代码:根据你的需求自己改改:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'province.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function loadXMLDoc()
{
xmlhttp = null;
var country = document.getElementById("country");
country.length = 1;
country.selectedIndex = 0;
var province = document.getElementById("province");
if(province.value == ""){
return ;
}
var url="http://localhost:8080/Ajax_Province/GetProvince?&province="+encodeURIComponent(province.value);
if (window.XMLHttpRequest) {// code for Firefox, Mozilla, IE7, etc.
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp != null) {
xmlhttp.onreadystatechange = state_Change;
xmlhttp.open("post", url, true);
xmlhttp.send(null);
} else {
alert("Your browser does not support XMLHTTP.");
}
}

function state_Change() {
var province = document.getElementById("province");
var country = document.getElementById("country");
if (xmlhttp.readyState == 4&&xmlhttp.status == 200) {// 4 = "loaded"
var serviceData = xmlhttp.responseText;
if(serviceData == null||serviceData == ""){
return;
}
var s = serviceData.split(",");
for(var i=0;i<s.length-1;i++){
country.options[i+1] = new Option(s[i],s[i]);
}
}
}




</script>
</head>

<body>
出生地:<select id="province" onchange="loadXMLDoc()">
<option value="">------请选择省-----</option>
<option value="江西省">江西省</option>
<option value="江苏省">江苏省</option>
<option value="浙江省">浙江省</option>
<option value="山东省">山东省</option>
<option value="辽宁省">辽宁省</option>
<option value="福建省">福建省</option>

</select>

<select id="country"><option value="">-----请选择市-----</option></select>
</body>
</html>
servlet:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.zjl.service.ProvinceService;


public class GetProvince extends HttpServlet {

/**
* Constructor of the object.
*/
public GetProvince() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request, response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List list = null;
ProvinceService provinceService = new ProvinceService();
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String strprovince = request.getParameter("province");
if(strprovince == null||"".equals(strprovince)){
return ;
}
String province = new String(strprovince.getBytes("ISO-8859-1"),"UTF-8");
list = provinceService.getCountry(province);//这个是查询数据库的你可以换你的对数据库的操作
if(list ==null){
return;
}
StringBuffer sb = new StringBuffer();
for(int i=0;i<list.size();i++){
String s = (String)list.get(i);
sb.append(s+",");
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print(sb);
out.flush();
out.close();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}

虽不简单 2011-11-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 kouyisc 的回复:]
对象的方式。。。如:person对象。包含id和名称name字段。。。

循环将名称person.name显示在option中供用户选择,选中以后显示对应的编号person.id就行了啊。。
[/Quote]

关键就是如何“选中以后显示对应的编号person.id就行了啊。。”?呢?
kouyiSC 2011-11-14
  • 打赏
  • 举报
回复
对象的方式。。。如:person对象。包含id和名称name字段。。。

循环将名称person.name显示在option中供用户选择,选中以后显示对应的编号person.id就行了啊。。
bj100 2011-11-14
  • 打赏
  • 举报
回复
selected
飓风zj 2011-11-14
  • 打赏
  • 举报
回复
啥意思啊
随风醉舞 2011-11-14
  • 打赏
  • 举报
回复
既然能获得值,获得编号也不是问题吧!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧