选择更改时用jQuery检测 [英] Detect with JQuery when a select changes

查看:26
本文介绍了选择更改时用jQuery检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Jqgrid,它动态生成这样的选择:

I have a Jqgrid which dinamically generates selects like this:

    <select id="won" style="width: 65px;">
       <option value="">-WON?</option>
       <option value="1" selected>Bet1</option>
       <option value="2" >Bet2</option>
       <option value="3" >Bet3</option>
    </select>

每一个都有不同的选择.我想检测一个选择何时发生变化,以便我可以将其保存在我的数据库中.

Each one have a different selected option. I would like to detect when one select changes so I can save it in my database.

我正在尝试:

         $('#won').change(function(){
               alert("PROBANDO");
          });

但根本不起作用.任何帮助将不胜感激.

But is not working at all. Any help will be apreciated Thanks.

推荐答案

问题是select是动态创建的,那么需要使用.on()

The problem is that the select are created dynamically, then you need to use .on()

试试这个:

         $(document).on('change','#won',function(){
               alert("PROBANDO");
          });

这篇关于选择更改时用jQuery检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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