在select JAVASCRIPT的特定元素上激活函数
我会确保选择中的项目不会激活我将解释的特定功能。 我有以下选择:在select JAVASCRIPT的特定元素上激活函数,javascript,Javascript,我会确保选择中的项目不会激活我将解释的特定功能。 我有以下选择: <select id='selection'> <!-->this is for the class<!--> <option>4B</option> <option>5B</option> </select> <select id='secondSelection'> <!-->this is f
<select id='selection'> <!-->this is for the class<!-->
<option>4B</option>
<option>5B</option>
</select>
<select id='secondSelection'> <!-->this is for the data to be loaded<!-->
</select>
这是为班级准备的
4B
5B
这是用于要加载的数据的
如果我选择4B必须加载与该类对应的所有学生,则学生在数组4B中。
如果改为选择5B,则必须能够在另一个加载中选择5B的内容。用户还可以决定选择这两个类
例如:
4B[在选择中选择]=>马里奥、路易吉、约翰现在在第二选择中加载
对于所有值,情况也是如此必须能够通过启用多个来完成相同的任务。
我已经在过去做了一个类似的代码,但这里的情况有点'不同,我想一个专家的帮助。和平 好吧,你能行
var b4 = ["Mario", "Luigi", "John"],
b5 = ["Some", "Other", "Names"],
elem = document.getElementById('selection');
elem.onchange = function () {
document.getElementById('secondSelection').innerHTML = this[elem.options[this.selectedIndex].text == "4B" ? "b4" : "b5 "].map(function (x) {
return "<option>" + x "</option>";
}).join();
};
var b4=[“马里奥”、“路易吉”、“约翰”],
b5=[“某些”、“其他”、“名称”],
elem=document.getElementById('selection');
elem.onchange=函数(){
document.getElementById('secondSelection')。innerHTML=this[elem.options[this.selectedIndex]。text==“4B”?“b4”:“b5”].map(函数(x){
返回“+x”;
}).join();
};
您可以使用
<select onchange="myFunction()">
函数myFunction(){
}
它也可以工作需要jQuery解决方案吗?不,我使用纯javascript不需要jQuery请发布您尝试过的内容,并具体解释您遇到的困难。有关已连接选择的问题已经被问了很多次。您必须收听选择上的
change
事件查看-->