如何立即触发一个dropdownlist事件? [英] How to fire an dropdownlist event instantaneously?

查看:119
本文介绍了如何立即触发一个dropdownlist事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPDATE2 :出于某种原因,'jquery-1.4.4-vsdoc.js'文件实际上是一个问题...该文件仅用于智能感知吗? ...我对此进行了评论,它现在可以正常工作..

UPDATE2 : The 'jquery-1.4.4-vsdoc.js' file was an issue for some reason actually...is that file only for intellisense ? ...i commented the include out for that and it works fine now..

更新:好的,所以当我使用原始js文件时,它可以正常工作- http://code.jquery.com/jquery-1.4.4.js

UPDATE: OK so it worked when I used the original js file- http://code.jquery.com/jquery-1.4.4.js

我有一个下拉列表:<%= Html.DropDownList("dropdownid", new SelectList(Model.WeightToLoseList, "Value", "Text")) %>

在我的jQuery中,我分配如下更改事件:

in my jQuery, I assign change event like this:

$('#dropdownid').change(function() {......});

但是,只有当我选择任何内容然后单击页面外部的任何地方时,此事件才会触发.但是我希望它可以立即工作并在我从下拉列表中选择项目后向我显示,而不是在我单击外部之后显示给我...这行为仅在chrome和firefox上重现.但是它在 IE8 上运行良好.有什么想法吗?

But this event only is firing when i select anything and then click anywhere outside on the page..but I want it to work instantly and show me once I select items from the dropdownlist and not after i click outside...this behaviour is reproduced only on chrome and firefox. But it works fine on IE8. Any ideas ?

推荐答案

Vincent Ramdhanie的答案是:

Vincent Ramdhanie's answer was:

$(document).ready(function(){
 var clicknum = 0;
 $("#dropdownid").click(function(){
        clicknum++;
        if(clicknum == 2){
            alert($(this).val());
                clicknum = 0;
        }
 });
});

这篇关于如何立即触发一个dropdownlist事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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