动态实现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 ");