如何级联jQuery Mobile组合框
How to cascade jQuery Mobile combo boxes
我开发了一个级联选择菜单,用于更新具有相同值的组合框。
我在更新多个组合框时遇到问题。例如,我设法将一个父组合框级联到它的子(a)组合框。但是我希望child(b)等动态更新。
我想到的解决方案是为这3个组合框创建单独的函数,每当其中任何一个发生更改时,它都会更新。当然,每个父级都有自己的子级(匹配值),因此更改子级组合框不会影响父级。
以下是我所写的内容:https://jsfiddle.net/1ospxyer/6/(请在JSFiddle的JQuery手机中加载-左侧)
var storeSiteList = $("#select-choice-1>option");
var storeBuildingList = $("#select-choice-2>option");
var storeLocationList = $("#select-choice-3>option");
function siteFilter() {
$("#select-choice-1").change(function () {
$("#select-choice-2").append(storeBuildingList);
var current_site = $(this).val();
$("#select-choice-2>option").each(function () {
if (current_site !== $(this).val()) {
$(this).remove();
$("#select-choice-2").selectmenu("refresh");
}
});
});
}
function buildingFilter() {
$("#select-choice-2").change(function () {
$("#select-choice-3").append(storeLocationList);
var current_building = $(this).val();
$("#select-choice-3>option").each(function () {
if (current_building !== $(this).val()) {
$(this).remove();
$("#select-choice-3").selectmenu("refresh");
}
});
});
}
function locationFilter() {
$("#select-choice-3").change(function () {
$("#inputFloor").val($(this).val());
});
}
siteFilter();
buildingFilter();
locationFilter();
有没有一种方法可以级联多个组合框(不仅仅是前两个)?
您只需在更新子组合后触发子组合上的更改事件,即可更新第三个组合。
$("#select-choice-1").change(function () {
$("#select-choice-2").append(storeBuildingList);
var current_site = $(this).val();
$("#select-choice-2>option").each(function () {
if (current_site !== $(this).val()) {
$(this).remove();
$("#select-choice-2").selectmenu("refresh");
}
});
//trigger change
$("#select-choice-2").change();
});
更新FIDDLE
相关文章:
- 无法从jquery Mobile导航栏重定向到另一个页面
- jquery mobile上多个页面上的一个表单
- window.location使用jquery mobile实现chrome跳转
- 防止jQuery Mobile中的ajax缓存
- 如何在JQUERY Mobile上放置谷歌地图
- JQuery Mobile Javascript复杂方程式
- jQuery Mobile Undefined不是一个函数
- jQuery mobile not going through ID
- 如何使用javascript或jquery mobile从url读取和显示XML文件
- jQuery Mobile Collapse上的AJAX请求
- 应用程序在呈现Jquery Mobile之前显示无样式的Html
- 如何在jQuery Mobile 1.4 Datepicker中创建事件
- UIWebview赢得't通过基本身份验证加载动态加载的资源(通过jQuery mobile)
- jQuery Mobile到其他页面的锚链接不起作用
- 如何在jQuery Mobile中设置100%宽度的输入类型日期
- JQuery Mobile破坏了我的布局:如何禁用自动打字
- 防止用户在jQuery Mobile中ajax加载页面时单击其他位置
- 根据手机上是否存在文件,在jQuery mobile中动态填充列表视图
- Image Sprites和jQuery Mobile Ajax导航的问题
- jQuery Mobile:如何在$.Mobile.changePage之前运行回调函数