你這個不能這樣寫
創(chuàng)新互聯(lián)公司是一家專業(yè)提供瑯琊企業(yè)網(wǎng)站建設(shè),專注與做網(wǎng)站、網(wǎng)站制作、H5網(wǎng)站設(shè)計、小程序制作等業(yè)務(wù)。10年已為瑯琊眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進行中。
你只能用ajax來做 只要其他條件變動 就觸發(fā)請求訪問后臺 然后后臺根據(jù)條件查詢相應(yīng)的出票方,以json格式傳到前臺,然后解析用js放入相應(yīng)的select標簽
至于ajax二級聯(lián)動 你自己百度下 一大把 原理都是ajax請求 js解析放入相應(yīng)的標簽
你可以通過 jquery 的ajax 訪問后臺獲取 json數(shù)據(jù) 。這樣就可以直接把 傳過來的接送數(shù)據(jù) 賦值給proData
還可以通過純jsp的方法
%
JSONObject json = JSONObject.fromObject(你訪問你后臺的方法返回的字符串數(shù)據(jù));
%
在js里面
var proData = eval("(%=json %)")
java中要實現(xiàn)二級聯(lián)動,應(yīng)該使用ajax技術(shù),實例如下:
var?req;
function?chooseEmp()
{
var?emp=?document.getElementById('empId');
var?url?=?"MagEmp?emp="+escape(emp.value);
if?(window.XMLHttpRequest)?{
req?=?new?XMLHttpRequest();
}else?if?(window.ActiveXObject)?{
req?=?new?ActiveXObject("Microsoft.XMLHTTP");
}
if(req){
req.open("GET",?url,?true);
req.onreadystatechange?=?callback;
req.send(null);???
}
}
function?callback()
{
if(req.readyState?==?4)
{
if(req.status?==?200)
{
parseMessage();
}else{
alert("Not?able?to?retrieve?description"+req.statusText);
}
}
}
function?parseMessage()
{
var?xmlDoc=req.responseXML.documentElement;
var?xSel=xmlDoc.getElementsByTagName('select');
var?select_root=document.getElementById('magId');
select_root.options.length=0;
for(var?i=0;ixSel.length;i++)
{
var?xValue=xSel[i].childNodes[0].firstChild.nodeValue;
var?xText=xSel[i].childNodes[1].firstChild.nodeValue;
var?option=new?Option(xText,xValue);
try{
select_root.add(option);
}catch(e){
}
}
}
//:ComboBoxText.java
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class ComboBoxText {
private String[][] xxx = {
{"浙江","杭州","溫州","紹興","舟山",},
{"江蘇","南京","無錫","徐州","蒙眬",},
{"上海","閔行區(qū)","普陀區(qū)","金山區(qū)",},
};
private Object[] a(){
Object[] os = new Object[xxx.length];
for(int i=0; ixxx.length; i++){
os[i]=xxx[i][0];
}
return os;
}
private Object[] b(Object a){
for(int i=0; ixxx.length; i++){
if(xxx[i][0].equals(a)){
Object[] o = new Object[xxx[i].length-1];
for(int j=0; jo.length; j++)
o[j]=xxx[i][j+1];
return o;
}
}
return new Object[]{};
}
public static void main(String[] args) {
final ComboBoxText ct = new ComboBoxText();
final JComboBox ca = new JComboBox(ct.a());
final JComboBox cb = new JComboBox();
ca.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
cb.removeAllItems();
Object selected = ca.getSelectedItem();
Object[] newItems = ct.b(selected);
for(int i=0; inewItems.length; i++)
cb.addItem(newItems[i]);
}
});
ca.setSelectedIndex(-1);
JFrame f = new JFrame();f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
f.add(ca);f.add(cb);f.setVisible(true);
f.setSize(200,100);
}
}
%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%
html
head
title/title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
style
body,select
{
font-size:9pt;
font-family:Verdana;
}
a
{
color:red;
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
/style
SCRIPT LANGUAGE="JavaScript"
!--
function Dsy()
{
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;iv;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v document.getElementById(s[v-1]).selectedIndex0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;iar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++vs.length){change(v);}
}
}
var dsy = new Dsy();
dsy.add("0",["1","2","3","4"]);
dsy.add("0_0",["11","12","13"]);
dsy.add("0_1",["21","22","23"]);
dsy.add("0_2",["31","32","33"]);
dsy.add("0_3",["41","42","43"]);
//--
/SCRIPT
SCRIPT LANGUAGE = JavaScript
var s=["s1","s2"];
var opt0 = ["請選擇","請選擇"];
function setup()
{
for(i=0;is.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
//--
/SCRIPT
/head
body bgcolor="#E0E0E0" onload="setup()"
form name="frm" action="11.jsp"
select id="s1" name="s1"option/option/select
select id="s2" name="s2"option/option/select
input type="submit" name="Submit" value="提交"
/form
/body
/html
11.jsp
html
head
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
titleInsert title here/title
/head
body
%
String s1 = request.getParameter("s1");
String s2 = request.getParameter("s2");
out.println(s1);
out.println(s2);
%
/body
/html
當前文章:二級聯(lián)動JAVA代碼 java實現(xiàn)二級聯(lián)動
鏈接地址:http://m.newbst.com/article20/hpddco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、網(wǎng)頁設(shè)計公司、服務(wù)器托管、網(wǎng)站營銷、建站公司、移動網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)