简体   繁体   English

JavaScript-下拉验证选择

[英]JavaScript - dropdown validation selection

I have 3 dropdowns , I would like to check in JavaScript that at least one selection has been made, if not display a message. 我有3个dropdowns ,如果没有显示消息,我想签入JavaScript至少进行了一次选择。 What would be the simplest way to do it in JavaScript? 用JavaScript做到这一点的最简单方法是什么?

id: dropdown1 id: dropdown2 id: dropdown3 id:dropdown1 id:dropdown2 id:dropdown3

Thanks 谢谢

// need to make sure the first dropdown option is blank, then... //需要确保第一个下拉选项为空白,然后...

var dd1 = document.getElementById('dropdown1'); var dd1 = document.getElementById('dropdown1');
var dd2 = document.getElementById('dropdown2'); var dd2 = document.getElementById('dropdown2');
var dd3 = document.getElementById('dropdown3'); var dd3 = document.getElementById('dropdown3');

if (
  (dd1.selectedIndex == 0) && 
  (dd2.selectedIndex == 0) && 
  (dd3.selectedIndex == 0)
) {  
  alert('need to select at least one')
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM