简体   繁体   English

如何根据我从选择组合中选择的选项显示不同的窗口?

[英]how can i show a different window depending on the option i choose from a selection combo?

I have this code我有这个代码

And I want to show a different message when I click in one of these options.当我单击其中一个选项时,我想显示不同的消息。

 document.getElementById("specialityAppointmentSelection").addEventListener('onchange', function(){ let specialityAppointmentSelection = document.getElementById("specialityAppointmentSelection"); let specialityOption = specialityAppointmentSelection.value; console.log(specialityOption); if(specialityOption === "1"){ console.log("medicina"); } else { console.log("enfermería"); } });
 <p>Selecciona el tipo de cita que desee: </p> <select id = "specialityAppointmentSelection"> <option value = "1">Medicina</option> <option value = "2">Enfermería</option> </select>

But I can't show anything in my console.log , what is the problem?但我无法在我的console.log中显示任何内容,这是什么问题?

You should use change rather than onchange like so .addEventListener('change', function(){你应该使用change而不是onchange像这样.addEventListener('change', function(){

 document.getElementById("specialityAppointmentSelection").addEventListener('change', function(){ let specialityAppointmentSelection = document.getElementById("specialityAppointmentSelection"); let specialityOption = specialityAppointmentSelection.value; console.log(specialityOption); if(specialityOption === "1"){ console.log("medicina"); } else { console.log("enfermería"); } });
 <p>Selecciona el tipo de cita que desee: </p> <select id = "specialityAppointmentSelection"> <option value = "1">Medicina</option> <option value = "2">Enfermería</option> </select>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据下拉选择显示/隐藏div? - How can I show/hide divs depending on dropdown selection? 如何根据下拉列表中的选定选项显示元素 - How can I show an element depending on selected option in a dropdown 我有一个选项表单,我想为我选择的选项标签的每个元素显示来自 JSON 文件的不同图像 - I have an option form and I would like to show a different image from a JSON file for each element of the option tag i choose 如何根据所显示的对象在单击时显示不同的文本? - How can I show different text on click depending on object shown? 如何在 html 页面中创建用于日期选择的组合框? - How can i create combo box for date selection in html page? 如何根据另一个下拉菜单的选择隐藏/显示一个下拉菜单? - How can I have one dropdown hide/show depending on the selection of another dropdown? 如何从window.selection()获取文本样式? - How can I get the text style from window.selection()? 如何在 javascript 中选择不同的时区? - How can I choose a different timezone in javascript? 我如何在反应中进行验证,如果我从下拉菜单中选择了一个选项,那么该选项将在另一个下拉菜单中被禁用 - How can I put validation in react, that if I have choose an option from a drop down, then that option will be disable in the other drop down menu 我如何使用javascript选择不同的2个单选按钮来填充选择选项列表 - how can i fill an select option list with the selection of different-2 radiobuttons using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM