切换第一下拉框,第二个下拉框跟着变。联动刷新
<script type="text/javascript">
var dirMap = new Map();
var uppeakMap = new Map();
var downpeakMap = new Map();
var timeMap = new Map();
$(function(){
debugger
init();
var data = ${data};
initEchart(data)
//切换方向下拉框
$("#dirSelect").change(function(){
var dirid = $(this).val();
debugger
var peakid = $("#peaksetionSelect option:selected").val();
debugger
createPeakSelect(dirMap.get(dirid));
getData(peakid,dirid);
});
//切换峰段下拉框
$("#peaksetionSelect").change(function(){
var peakid = $(this).val();
var dirid = $("#dirSelect option:selected").val();
getData(peakid,dirid);
});
});
function getData(peakid,dirid){
debugger
var url = "${ContextPath}/generic/workplan/flush?IntervalList="+$.queryString("IntervalList")+
"&lineId="+$.queryString("lineId")+"&categoryId="+$.queryString("categoryId")+"&peaksetionId="+peakid+"&dir="+dirid;
var data = $.ajax({
url : url,
async : false,
type : "POST",
data : {},
success: function(data){
debugger
if(data) {
data = eval("("+data+")");
initEchart(data);
}
}
});
}
function createPeakSelect(peakMap){
var selectPeak=$("#peaksetionSelect");//峰段下拉框
peakMap.each(function(peakid){
if(!dirRepeat("peaksetionSelect", peakid)){
var peakOption=$("<option></option>");
peakOption.val(peakid);
peakOption.text(peakMap.get(peakid));
selectPeak.append(peakOption);
}
});
}
function init(){
var IntervalList = $.queryString("IntervalList");
IntervalList=JSON.parse(IntervalList); //可以将json字符串转换成json对象
var selectObj = $("#dirSelect");//方向下拉框
var selectPeak=$("#peaksetionSelect");//峰段下拉框
for(var i =0 ;i<IntervalList.length;i++){
var peakid = IntervalList[i].PEAK_SECTION;//峰段id
var peakName=IntervalList[i].PEAK_SECTIONDESC;//峰段名称
var startTime=IntervalList[i].STARTTIME;//峰段开始时间
// alert(startTime);
var endTime=IntervalList[i].ENDTIME;//峰段结束时间
timeMap.put(peakid,startTime+"-"+endTime);
var dirid=IntervalList[i].OPM_DIRECTION;//双向id
var dirName = dirid=="0"?"上行":"下行";//方向返回0,表示是上行,否则下行
if(dirid=="0"){
debugger
if(!uppeakMap.containsKey(peakid)){
//?放峰段的起始时间吗
uppeakMap.put(peakid,peakName);
}
dirMap.put(dirid,uppeakMap);
}else{
debugger
if(!downpeakMap.containsKey(peakid)){
downpeakMap.put(peakid,peakName);
}
dirMap.put(dirid,downpeakMap);
}
//去掉重复
if(!dirRepeat("dirSelect",dirid)){
var dirOption = $("<option></option>");
dirOption.val(dirid);
dirOption.text(dirName);
selectObj.append(dirOption);
}
if(!dirRepeat("peaksetionSelect", peakid)){
var peakOption=$("<option></option>");
peakOption.val(peakid);
peakOption.text(peakName);
selectPeak.append(peakOption);
}
}
dirMap.each(function(dir){
dirMap.get(dir);
});
}
//去掉重复
function dirRepeat(id,value){
var returnValue = false;
$("#"+id+" option").each(function(){
if($(this).val() == value){
returnValue = true;
}
});
return returnValue;
}
<body>
<h3>运力、满意度分析</h3>
<div >
<select id="dirSelect" ></select>
<select id="peaksetionSelect"></select>
</div>
var dirMap = new Map();
var uppeakMap = new Map();
var downpeakMap = new Map();
var timeMap = new Map();
$(function(){
debugger
init();
var data = ${data};
initEchart(data)
//切换方向下拉框
$("#dirSelect").change(function(){
var dirid = $(this).val();
debugger
var peakid = $("#peaksetionSelect option:selected").val();
debugger
createPeakSelect(dirMap.get(dirid));
getData(peakid,dirid);
});
//切换峰段下拉框
$("#peaksetionSelect").change(function(){
var peakid = $(this).val();
var dirid = $("#dirSelect option:selected").val();
getData(peakid,dirid);
});
});
function getData(peakid,dirid){
debugger
var url = "${ContextPath}/generic/workplan/flush?IntervalList="+$.queryString("IntervalList")+
"&lineId="+$.queryString("lineId")+"&categoryId="+$.queryString("categoryId")+"&peaksetionId="+peakid+"&dir="+dirid;
var data = $.ajax({
url : url,
async : false,
type : "POST",
data : {},
success: function(data){
debugger
if(data) {
data = eval("("+data+")");
initEchart(data);
}
}
});
}
function createPeakSelect(peakMap){
var selectPeak=$("#peaksetionSelect");//峰段下拉框
peakMap.each(function(peakid){
if(!dirRepeat("peaksetionSelect", peakid)){
var peakOption=$("<option></option>");
peakOption.val(peakid);
peakOption.text(peakMap.get(peakid));
selectPeak.append(peakOption);
}
});
}
function init(){
var IntervalList = $.queryString("IntervalList");
IntervalList=JSON.parse(IntervalList); //可以将json字符串转换成json对象
var selectObj = $("#dirSelect");//方向下拉框
var selectPeak=$("#peaksetionSelect");//峰段下拉框
for(var i =0 ;i<IntervalList.length;i++){
var peakid = IntervalList[i].PEAK_SECTION;//峰段id
var peakName=IntervalList[i].PEAK_SECTIONDESC;//峰段名称
var startTime=IntervalList[i].STARTTIME;//峰段开始时间
// alert(startTime);
var endTime=IntervalList[i].ENDTIME;//峰段结束时间
timeMap.put(peakid,startTime+"-"+endTime);
var dirid=IntervalList[i].OPM_DIRECTION;//双向id
var dirName = dirid=="0"?"上行":"下行";//方向返回0,表示是上行,否则下行
if(dirid=="0"){
debugger
if(!uppeakMap.containsKey(peakid)){
//?放峰段的起始时间吗
uppeakMap.put(peakid,peakName);
}
dirMap.put(dirid,uppeakMap);
}else{
debugger
if(!downpeakMap.containsKey(peakid)){
downpeakMap.put(peakid,peakName);
}
dirMap.put(dirid,downpeakMap);
}
//去掉重复
if(!dirRepeat("dirSelect",dirid)){
var dirOption = $("<option></option>");
dirOption.val(dirid);
dirOption.text(dirName);
selectObj.append(dirOption);
}
if(!dirRepeat("peaksetionSelect", peakid)){
var peakOption=$("<option></option>");
peakOption.val(peakid);
peakOption.text(peakName);
selectPeak.append(peakOption);
}
}
dirMap.each(function(dir){
dirMap.get(dir);
});
}
//去掉重复
function dirRepeat(id,value){
var returnValue = false;
$("#"+id+" option").each(function(){
if($(this).val() == value){
returnValue = true;
}
});
return returnValue;
}
<body>
<h3>运力、满意度分析</h3>
<div >
<select id="dirSelect" ></select>
<select id="peaksetionSelect"></select>
</div>
...全文
相关推荐
最简单的下拉框联动不刷新页面示例
最简单的下拉框联动不刷新页面示例 用AJAX控件 !!!!!!!!!!!!!!!!!!
FastAdmin Selectpage动态数据绑定与交互实战
本文深入解析FastAdmin框架中Selectpage组件的动态数据绑定与交互实战。通过核心方法`selectPageData`实现下拉框的智能联动,详细介绍了从基础初始化、后端接口适配到多级联动与事件监听的完整解决方案,并分享了性能优化与常见问题排查技巧,帮助开发者高效构建复杂的动态表单交互。
三级联动下拉框实现
三级联动下拉框实现,包含行政编码,身份证前5位,一个文件实现
layui实现下拉框三级联动
主要为大家详细介绍了layui实现下拉框三级联动,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
javascript实现二级联动下拉框
javascript实现二级联动下拉框,多多支持:)


