根据下拉选项进行切换 [英] Switching depending on Dropdown option
本文介绍了根据下拉选项进行切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文本文件s1.text'
和s2.text
.
s1.text的内部包含以下文本.
s1.text has the following text inside.
<option value='val11'>text11</option>
<option value='val12'>text12</option>
<option value='val13'>text13</option>
s2.text的内部包含以下文本.
s2.text has the following text inside.
<option value='val21'>text21</option>
<option value='val22'>text22</option>
<option value='val23'>text23</option>
在同一文件夹中,我的index.html
具有以下内容.
In the same folder, I have the index.html
with the following content.
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Course Check List</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<script>
$(function () {
$('#sctdd').change(function () {
*
});
});
</script>
</head>
<body>
<form name='form_last'>
<br>
<select id='sctdd' name='sct'>
<option value='224' selected>2015-2016 Spring</option>
<option value='223'>2015-2016 Fall</option>
</select>
<select id='crsdd' name='crs'>
</select>
<br>
<input type='submit' name='tus' value='Submit'>
</form>
</body>
</html>
我可以通过代码加载s1.text
或s2.text
I can load s1.text
or s2.text
by the code
$('#crsdd').load("s1.txt");
以*的速度.但是,根据sctdd
的值,我无法切换为加载s1.text
或s2.text
.如果值为223可以加载s1,如果值为224可以加载s2
in the pace of *. However, I can not make a switch to load s1.text
or s2.text
depending on the value of sctdd
. Is it possible to load s1 if value is 223 and s2 if value is 224
推荐答案
这可以解决问题:
$(function () {
$('#sctdd').change(function () {
var selectedOption = $(this).val();
switch (selectedOption) {
case '224':
$('#crsdd').load("s1.txt");
break;
case '223':
$('#crsdd').load("s2.txt");
break;
default:
}
});
});
这篇关于根据下拉选项进行切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文