首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

动态实现Select?解决思路

2012-03-15 
动态实现Select?有数据区,街道在数据库中我要动态的在Select中选择区后现在区内的各街道怎样实现呢?可以通

动态实现Select?
有数据区,街道在数据库中
我要动态的在Select中选择区后现在区内的各街道
怎样实现呢?

可以通过Submit在JavaBean中实现
但是页面中已经有Submit了
怎么实现呢?

[解决办法]
看看Ajax方面的资料吧,这种联动菜单的东东,用Ajax解决起来方便的很呀
[解决办法]
baidu下 二级联动或三级联动 好多的
在csdn上也提了n次这个问题了
自己找找把
[解决办法]
推荐利用AJAX来实现你想要的功能~!
[解决办法]
AJAX轻松解决!!
[解决办法]
这是我在项目中写的select,只不过我用的是它的list(下拉列表,即select的multiple=true),你可以参照一下:

1,根据id,name创建一个option
function addUser(id, name) {
var oOption = document.createElement( "OPTION ");
oOption.text = name;
oOption.value = id;
document.getElementById( "groupdest ").add(oOption);
}
2,初始化
function initGroupDest() {
var ids = document.getElementById( "ids ").value;
var names = document.getElementById( "names ").value;
if (ids == null || ids == ' ') {
return;
}
var idArr = ids.split( ", ");
var nameArr = names.split( ", ");
var len = idArr.length;
for (var i = 0; i < len - 1; i ++) {
addUser(idArr[i], nameArr[i]);
}
}
3,删除:
function removeUser() {
var oSelect = document.getElementById( "groupdest ");
for (var i = 0; i < oSelect.length; i++) {
var option = oSelect.options[i];
if (option.selected == true) {
oSelect.remove(i);
return;
}
}
}
4,校验:
function checkData() {
var ids = document.getElementById( "ids ").value;
if (ids == null || ids == " ") {
return false;
}
return true;
}
5,提交:
function sendGroup() {
var oSelect = document.getElementById( "groupdest ");
var ids = " ";
var names = " ";
for (var i = 0; i < oSelect.length; i++) {
var option = oSelect.options[i];
ids += option.value + ", ";
names += option.text + ", ";
}
document.getElementById( "ids ").value = ids;
document.getElementById( "names ").value = names;
if (checkData()) {
var fmObj = document.forms[0];
fmObj.action = "sendMain.do ";
fmObj.method = "post ";
fmObj.submit();
}
}
其中用到了3个控件:
<html:hidden property= "ids "/>
<html:hidden property= "names "/>
<select id= "groupdest "
name= "groupdest "
size= "15 "
style= "width:200 "
multiple= "true ">
</select>

你可以参考参考~~
[解决办法]
<html>
<head>
<title> test </title>
<meta httq-equiv= "content-type " content= "context/html;charset=gbk "/>
<SCRIPT LANGUAGE= "JavaScript ">
<!--
var select2 = new Array();
window.onload = function ()
{
select2[0] = new Option( "0000 ", "0000 ");
select2[1] = new Option( "0001 ", "0001 ");
select2[2] = new Option( "0100 ", "0100 ");


select2[3] = new Option( "0101 ", "0101 ");
select2[4] = new Option( "0200 ", "0200 ");
select2[5] = new Option( "0101 ", "0101 ");

selectFirst( "00 ");
}

function selectFirst(first)
{
var frm = document.form1;
frm.s2.options.length = null;
var index = 0;
for (i = 0; i < select2.length; i++)
{
if (select2[i].value.indexOf(first) == 0)
{
frm.s2.options[index] = select2[i];
index++;
}
}
}
//-->
</SCRIPT>
</head>

<body>
<form name= "form1 ">
<select name= "s1 " onChange= "selectFirst(this.value) ">
<option value= "00 "> 00 </option>
<option value= "01 "> 01 </option>
<option value= "02 "> 02 </option>
</select>
<select name= "s2 ">
</select>
</form>
</body>
</html>

热点排行