下拉菜单上的jQuery功能 [英] jquery function on dropdown select

查看:65
本文介绍了下拉菜单上的jQuery功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择了某个下拉选项,我需要运行一个jquery函数.

I need to run a jquery function if a certain dropdown option is selected.

<select name=dropdown size=1>
    <option value=1>option 1</option>
    <option value=2>option 2</option>
</select>

我已经准备好函数中的命令,只是不确定如何使它生效,如果下拉菜单中当前选项2当前处于活动状态,则运行该函数.

I have the commands in the function ready, Im just not sure on how to make it so if option 2 is currently active in the dropdown, then run the function.

(下拉菜单中没有提交按钮,我希望它在用户突出显示该选项时运行)

(dropdown doesnt have a submit button, i want it ran when the user highlights the option)

推荐答案

尝试此演示 http ://jsfiddle.net/JGp9e/

这将对您有帮助!

代码

$('select[name="dropdown"]').change(function(){

    if ($(this).val() == "2"){
        alert("call the do something function on option 2");
     }        
});​

HTML

<select name="dropdown" size=1>
    <option value="1">option 1</option>
    <option value="2">option 2</option>
</select>​

这篇关于下拉菜单上的jQuery功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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