如何根据活动下拉选择定义条件变量
How to define a conditional variable based on active drop-down selection
我使用 jquery 'chosen' 库创建了一个简单的表单。此表单构建一个 iframe src,其中 url 包含用户所做的选择。
一个要求是只允许用户从前两个下拉菜单(AttributeTree OR Disease)中的一个中进行选择,我已经成功地做到了,其中未使用的下拉菜单被禁用.
现在我遇到的问题是我的变量 URL:
URL = reportURL + Tree + Disease + Country + Gender
我需要它是动态的,这样当用户选择了一个 AttributeTree(下拉列表 1)时,URL 应该是
URL = reportURL + Tree + Country + Gender
..当用户选择疾病(下拉列表 2)时,URL 应该是
URL = reportURL + Disease + Country + Gender
如果我保持原样,它会在我的 URL 中包含冗余过滤器和文本(对于未使用的过滤器),这会在无效 URL 中创建。
我有一个 fiddle here 用来创建它。
您可以使用jQuery "is"函数来检查它是否被禁用。
这是我的代码。
var Tree = $("#Selection1").is(":disabled")?"":"Trees/JDAttribute2 in (" + $("#Selection1").val() + ") and ";
var Disease = $("#Selection2").is(":disabled")?"":"Diseases/DiseaseKey in (" + $("#Selection2").val() + ") and ";
var Country = "Countries/CountryKey in (" + $("#Selection3").val() + ") and ";
var Gender = "Genders/GenderKey in (" + $("#Selection4").val() + ")";
var URL = reportURL + Tree + Disease + Country + Gender ;
我保存了你的fiddle。
我使用 jquery 'chosen' 库创建了一个简单的表单。此表单构建一个 iframe src,其中 url 包含用户所做的选择。
一个要求是只允许用户从前两个下拉菜单(AttributeTree OR Disease)中的一个中进行选择,我已经成功地做到了,其中未使用的下拉菜单被禁用.
现在我遇到的问题是我的变量 URL:
URL = reportURL + Tree + Disease + Country + Gender
我需要它是动态的,这样当用户选择了一个 AttributeTree(下拉列表 1)时,URL 应该是
URL = reportURL + Tree + Country + Gender
..当用户选择疾病(下拉列表 2)时,URL 应该是
URL = reportURL + Disease + Country + Gender
如果我保持原样,它会在我的 URL 中包含冗余过滤器和文本(对于未使用的过滤器),这会在无效 URL 中创建。
我有一个 fiddle here 用来创建它。
您可以使用jQuery "is"函数来检查它是否被禁用。 这是我的代码。
var Tree = $("#Selection1").is(":disabled")?"":"Trees/JDAttribute2 in (" + $("#Selection1").val() + ") and ";
var Disease = $("#Selection2").is(":disabled")?"":"Diseases/DiseaseKey in (" + $("#Selection2").val() + ") and ";
var Country = "Countries/CountryKey in (" + $("#Selection3").val() + ") and ";
var Gender = "Genders/GenderKey in (" + $("#Selection4").val() + ")";
var URL = reportURL + Tree + Disease + Country + Gender ;
我保存了你的fiddle。