Javascript 如何通过选择条件下拉列表显示错误弹出窗口或警报消息

Javascript 如何通过选择条件下拉列表显示错误弹出窗口或警报消息,javascript,jquery,html,Javascript,Jquery,Html,我在hover上创建了一个过滤下拉列表,通过从第一个下拉列表中选择hover上的国家名称,相应的目的地将出现在hover上的第二个下拉列表中 首先,如果鼠标悬停在目的地下拉列表上而不是国家,则需要显示一条错误消息,如“选择国家优先” 这是完整的代码 函数更改DDL(obj){ var text=obj.options[obj.selectedIndex].text; var ddl2=document.querySelectorAll(“#IOOperation option”); 对于(变量

我在hover上创建了一个过滤下拉列表,通过从第一个下拉列表中选择hover上的国家名称,相应的目的地将出现在hover上的第二个下拉列表中

首先,如果鼠标悬停在目的地下拉列表上而不是国家,则需要显示一条错误消息,如“选择国家优先”

这是完整的代码

函数更改DDL(obj){
var text=obj.options[obj.selectedIndex].text;
var ddl2=document.querySelectorAll(“#IOOperation option”);
对于(变量i=1;i-1)
option.style.display='none'
}
如果(文本=‘印度’){
if(['Bangalore'、'Delhi'、'Gujarat'、'Kerala'、'Kutch Desert'、'South Kerala'、'Tamil Nadu Forests'、'Mysore'].indexOf(option.text)>-1)
option.style.display='block'
}
如果(文本==“斯里兰卡”){
if(['slianka',].indexOf(option.text)>-1)
option.style.display='block'
}
如果(文本==“瑞典”){
if(['Sweden'].indexOf(option.text)>-1)
option.style.display='block'
}
}
}
变量CountryArray=[
[“班加罗尔”、“德里”、“古吉拉特邦”、“喀拉拉邦”、“卡奇沙漠”、“南喀拉拉邦”、“泰米尔纳德邦森林”、“迈索尔”],
[“瑞典”],
[“斯里兰卡”]
];
函数DropNew(){
var index=document.getElementById(“iFunction”)。选择索引-1;
如果(索引>=0){
document.getElementById(“IOOperation”).size=countryArrays[index]。长度+1;
}
}
函数DropList(){
var n=document.getElementById(“iFunction”).options.length;
document.getElementById(“iFunction”).size=5;
}
功能手柄选择(elm){
window.location=elm.value;
}
选项:悬停{
背景#428ffa;
颜色:白色;
}
#手术,
#iFunction{
溢出:隐藏;
边框:2件纯黑;
}
.隐藏{
显示:无;
}

选择一个国家
印度
斯里兰卡
瑞典
选择一个目的地
班加罗尔
德里
古吉拉特邦
喀拉拉邦
卡奇沙漠
南喀拉拉邦
泰米尔纳德邦森林
迈索尔
斯里兰卡
瑞典

只需检查
选择的索引即可:

function DropNew() {
    if(0 === document.getElementById("iFunction").selectedIndex){
        alert('Please select country !');
        return;
    }
     /* TO DO */
}
函数更改DDL(obj){
var text=obj.options[obj.selectedIndex].text;
var ddl2=document.querySelectorAll(“#IOOperation option”);
对于(变量i=1;i-1)
option.style.display='none'
}
如果(文本=‘印度’){
if(['Bangalore'、'Delhi'、'Gujarat'、'Kerala'、'Kutch Desert'、'South Kerala'、'Tamil Nadu Forests'、'Mysore'].indexOf(option.text)>-1)
option.style.display='block'
}
如果(文本==“斯里兰卡”){
if(['slianka',].indexOf(option.text)>-1)
option.style.display='block'
}
如果(文本==“瑞典”){
if(['Sweden'].indexOf(option.text)>-1)
option.style.display='block'
}
}
}
变量CountryArray=[
[“班加罗尔”、“德里”、“古吉拉特邦”、“喀拉拉邦”、“卡奇沙漠”、“南喀拉拉邦”、“泰米尔纳德邦森林”、“迈索尔”],
[“瑞典”],
[“斯里兰卡”]
];
函数DropNew(){
var index=document.getElementById(“iFunction”)。选择索引-1;
如果(索引>=0){
document.getElementById(“IOOperation”).size=countryArrays[index]。长度+1;
}否则{
$(“#弹出窗口”).show();
}
}
函数hidePopup(){
$(“#弹出”).hide();
}
函数DropList(){
var n=document.getElementById(“iFunction”).options.length;
document.getElementById(“iFunction”).size=5;
}
功能手柄选择(elm){
window.location=elm.value;
}
选项:悬停{
背景#428ffa;
颜色:白色;
}
#手术,
#iFunction{
溢出:隐藏;
边框:2件纯黑;
}
.隐藏{
显示:无;
}

选择一个国家
印度
斯里兰卡
瑞典
选择一个目的地
班加罗尔
德里
古吉拉特邦
喀拉拉邦
卡奇沙漠
南喀拉拉邦
泰米尔纳德邦森林
迈索尔
斯里兰卡
瑞典
请先选择国家/地区

谢谢您的回复@Arvind,我可以在选择的目的地附近看到错误弹出窗口吗?我可以在选择的目的地附近看到错误弹出窗口吗?非常感谢您的回答,我可以在选择的目的地附近看到错误弹出窗口吗only@Saif现在检查一下。如果你需要一些解释,就这么说:)这正是我所需要的。