我从下拉菜单获取了一个值,我能将它与一个字符串进行比较吗?

4 浏览
0 Comments

我从下拉菜单获取了一个值,我能将它与一个字符串进行比较吗?

这个问题已经有答案了

使用JavaScript获取下拉列表的选定值

我所拥有的只是这个,但我无法从下拉菜单中得到任何值供JavaScript进行字符串比较。

    // JavaScript Document
var singleMulticontainer = document.getElementById("singleMultiContainer");
var singleMultiValue =  singleMultiContainer.options[singleMultiContainer.selectedIndex].value;
var nextButton = document.getElementById("nextButton");
var multipleSetWindow = "window.location='multiSet.html'"
if(singleMultiValue == "multi"){
    document.getElementById("nextButton").setAttribute("data-location", "multiSet.html");
}
else{
    alert("notworking");
}

而下拉菜单是这个:我如何从单个或多个容器选项中获得值?

 

Select Station:

 

Select Sample Medium:

 

Begin Date

 

Hydrologic Event:

 

Add:

 

Analyses Requested:(Applies to all samples)

Concentration Sand-fine break**  Sand analysis** Turbidity Loss-on-ignition**  Dissolve solids Specific conductance Full-size fractions**

 

admin 更改状态以发布 2023年5月23日
0
0 Comments

Fiddle

你忘了给你的选择器添加ID。我添加了

Select Sample Medium:

Begin Date

Hydrologic Event:

Add:

Analyses Requested:(Applies to all samples)

Concentration Sand-fine break**  Sand analysis** Turbidity Loss-on-ignition**  Dissolve solids Specific conductance Full-size fractions**

JS

// JavaScript Document
var singleMultiContainer = document.getElementById("singleMultiContainer");
var singleMultiValue = singleMultiContainer.options[singleMultiContainer.selectedIndex].value;
var nextButton = document.getElementById("nextButton");
var multipleSetWindow = "window.location='multiSet.html'"
if (singleMultiValue == "multi") {
    document.getElementById("nextButton").setAttribute("onclick", "window.location='multiSet.html'");
} else {
    alert("notworking");
}

0