选择下拉菜单中的特定值时发出警报 [英] Alert when a particular value from dropdown is selected

查看:91
本文介绍了选择下拉菜单中的特定值时发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个不受我控制的网站上有一个下拉菜单(选择),但它可以通过javascript,html,jquery..etc进行修改(他们已经提供了网页小程序)



此下拉列表可以标识为ID'Zdd_1'。所有我想要的,如果用户在下拉列表中选择是,那么只有一个警报应该来。当用户导航到页面时。下拉可能是Yes或其他值,但我不在乎。



只有当下拉状态从任何值变为YES时,才需要此警报。我对jquery和ajax没什么了解,所以如果这可以简单地完成(意思就是使用javascript),那就太好了。 解决方案

试试这个

  var dropdown = document.getElementById(Zdd_1); 
dropdown.onchange = function(event){
if(dropdown.value ==Yes){
alert(Your message)
}
}

或点击此处工作演示


I have a Dropdown(select) in a website that is not controlled by me.But it can be modified by javascript,html,jquery..etc(they have provided web applet for doing so)

This dropdown can be identified an ID 'Zdd_1'. All i want if the user selects "Yes" in the dropdown then only then an alert should come. W hen the user navigates to the page. the dropdown might be Yes or some other value, but i dont care then.

I need this alert only when the state of the drop down changes from any value to "YES". I am not much into jquery and ajax, so if this can be done done simply( mean just using javascript)it would be great.

解决方案

Try this

    var dropdown = document.getElementById("Zdd_1");
    dropdown.onchange = function(event){
       if(dropdown.value=="Yes"){
         alert("Your message")
       }
    }

or check here working demo

这篇关于选择下拉菜单中的特定值时发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆