动态选择选项在灯箱中失败
Dynamic select options failing in lightbox
我有一个用于容纳表单的灯箱。有两个选择,选择英国或美国,每个都有自己的列表关联到它。
我已经创建了这个背后的逻辑,但在灯箱之外,它可以工作,但是一旦添加进去,它就会失败,并且当您选择任何一个国家时,它不会切换到相关选项?
演示小提琴这是脚本,我也使用lightbox featherlight。
<select class="country">
<option value="US">US</option>
<option value="UK">UK</option>
</select>
<select class="model">
<option></option>
</select>
<script>
$(document).ready(function() {
var selectValues = {
"UK": {
"County1": "",
"County2": ""
},
"US": {
"State1": "",
"State2": ""
}
};
var $vendor = $('select.country');
var $model = $('select.model');
$vendor.change(function() {
$model.empty().append(function() {
var output = '';
$.each(selectValues[$vendor.val()], function(key, value) {
output += '<option>' + key + '</option>';
});
return output;
});
}).change();
});
</script>
Lightbox创建了一个div的副本。当您第一次加载对话框时,您必须将选择框的事件连接起来。幸运的是,您可以获得对刚刚打开的对话框的引用。
$("#openDialogButton").click(function () {
var dlg = $.featherlight("#fl1",
{
otherClose: ".btn", //any .btn will close the dialog
closeOnEsc: true
}
); //open the featherlight dialog
//FIND THE SELECT BOXES within the dialog you have just opened
var $vendor = dlg.$content.find('select.country');
var $model = dlg.$content.find('select.model');
$vendor.change(function () {
$model.empty().append(function () {
var output = '';
$.each(selectValues[$vendor.val()], function (key, value) {
output += '<option>' + key + '</option>';
});
return output;
});
}).change();
});
当你保存对话框的结果时,你不能使用$("select.model")。你必须从这个对象开始导航,例如
$("#dialogOKButton").click(function () {
var theCommentText = $("#commentText").val(); // null!
theCommentText = $(
$(this).parent()
).find("#commentText")
.val(); // have to navigate from this
alert("you entered this text "
+ theCommentText + " and clicked OK");
});
相关文章:
- 在我的情况下,使用带有变量失败的 jquery 选择器
- Jquery选择菜单选项在页面刷新时失败
- 由于adblock,Javascript Ajax请求在chrome中失败,我有什么选择
- Jquery 悬停函数在将鼠标悬停在选择框上时会失败
- 复选框选择/取消选择触发器第一次工作,但在随后的尝试中失败
- 使用 jquery 填充选择选项失败
- 为什么这个jQuery颜色选择器在引导模式中失败
- IE7 jquery 选择器返回“失败”
- 在我的情况下,任何使用 * 的选择器都失败了
- 为什么这个选择菜单在jQuery和JQM的新版本组合中失败
- 警告:失败的 propType:在“维度选取器”中未指定所需的属性“维度名称”.检查“连接(维度选择器)”的渲染方法
- 表单选择 GT 9 时脚本失败
- 谷歌数据存储查询中的多项选择抛出 API 错误:前提条件节点中失败错误
- 选择菜单项重置为默认值失败
- 当选择包含*时,使用ADO到Oracle服务器的查询失败未指定错误
- .id()方法在jQuery选择器上失败
- 为什么JQuery NOT选择器在类型提交时失败,但在类型按钮上有效
- 如果一个页面或网站已经有一个版本的Jquery chrome扩展失败.我想Jquery选择脚本
- Ng-repeat适用于<
- < light >等,但在选择完全相同的源时失败
- 动态选择选项在灯箱中失败