【发布时间】:2016-01-10 19:15:12
【问题描述】:
我对编程很陌生,希望能在这个问题上得到一些帮助。我的网页上有一个包含六个项目的下拉列表。我想打开一个与每个下拉选项关联的唯一对话框。我不想在打开页面时显示任何对话框,但在用户从下拉菜单中选择一个选项之前将它们隐藏起来。我给每个对话框 div 赋予了一个“隐藏答案”类,这样我就可以在打开页面时将它们隐藏起来。我所拥有的是在页面刷新时显示对话框,而不是在选择下拉项时。我正在使用 jQuery UI。
<script>
$(document).ready(function () {
$(".hide-answer").dialog({
autoOpen: false
});
var selPermit = document.getElementById("permit");
if (selPermit.selectedIndex === 1) {
$("#answer-1").dialog('open');
}
else if (selPermit.selectedIndex === 2) {
$("#answer-2").dialog('open');
}
else if (selPermit.selectedIndex === 3) {
$("#answer-3").dialog('open');
}
else if (selPermit.selectedIndex === 4) {
$("#answer-4").dialog('open');
}
else if (selPermit.selectedIndex === 5) {
$("#answer-5").dialog('open');
}
else if (selPermit.selectedIndex === 6) {
$("#answer-6").dialog('open');
};
});
</script>
<div id="permitForm" class="grouped">
<h2>Do I Need A Permit?</h2>
<select name="types" id="permit">
<option selected="selected" value="">-- select type --</option>
<option value="First">First</option>
<option value="Second">Second</option>
<option value="Third">Third</option>
<option value="Fourth">Fourth</option>
<option value="Fifth">Fifth</option>
<option value="Sixth">Sixth</option>
</select>
</div>
<div class="hide-answer" id="answer-1" title="First Condition">
<p>This is the description of when a first condition is needed.</p>
</div>
<div class="hide-answer" id="answer-2" title="Second Condition">
<p>This is the description of when a second condition is needed.</p>
</div>
<div class="hide-answer" id="answer-3" title="Third Condition">
<p>This is the description of when a third condition is needed.</p>
</div>
<div class="hide-answer" id="answer-4" title="Fourth Condition">
<p>This is the description of when a fourth condition is needed.</p>
</div>
<div class="hide-answer" id="answer-5" title="Fifth Condition">
<p>This is the description of when a fifth condition is needed.</p>
</div>
<div class="hide-answer" id="answer-6" title="Sixth Condition">
<p>This is the description of when a sixth condition is needed.</p>
</div>
</div>
</div>
【问题讨论】:
-
这是一个用于测试的小提琴:jsfiddle.net/Twisty/pnd51hau
-
欢迎来到 Stack Overflow。首先,
.dialog()只是 JQuery UI 的一个特性。你在测试中使用它吗?
标签: javascript jquery-ui drop-down-menu dialog selectedindex