简体   繁体   English

jQuery更改根本不会触发

[英]JQuery Change not triggering at all

i have a simple drop down as follows 我有一个简单的下拉列表如下

 <select id="drg-select" name="drg-select">
<option>Select DRG</option>
<option value="1"> PSYCHOSES</option>
<option value="2"> HEART FAILURE & SHOCK W CC</option>
<option value="3"> MAJOR JOINT REPLACEMENT OR REATTACHMENT OF LOWER EXTREMITY W/O MCC</option>
<option value="4"> SEPTICEMIA OR SEVERE SEPSIS W/O MV 96+ HOURS W MCC</option>
<option value="5"> INTRACRANIAL HEMORRHAGE OR CEREBRAL INFARCTION W CC</option>
<option value="6"> CHRONIC OBSTRUCTIVE PULMONARY DISEASE W CC</option>........
</select>

and this is how i am handling the Change event 这就是我处理Change事件的方式

       jQuery('select[name="drg-select"]').change(function() {
                alert('i am here');
            });

its pretty simple but it is not triggered at all please tell me , what i am missing. 它非常简单,但是根本不会触发,请告诉我,我缺少什么。 Also i have tested other events like ready etc and my JS/Jquery is already linked. 我也测试了其他事件,如ready等,并且我的JS / Jquery已链接。

Your code is working correctly. 您的代码正常工作。 May be you have not binded the event on correct time. 可能是您没有在正确的时间绑定事件。 Try binding the event on document ready. 尝试将事件绑定到文档就绪。

Working Demo 工作演示

$(document).ready(function(){
jQuery('select[name="drg-select"]').change(function() {
            alert('i am here');
        });
}); 

You should include the JQuery core file and under that you need to write the your script: 您应该包括JQuery核心文件,并在其下编写脚本:

Code for including JS and Jquery code: 包含JS和Jquery代码的代码:

<script src="Scripts/jquery-1.7.2.js" type="text/javascript"></script>
$(document).ready(function(){

$("#drg-select").change(function() {
       alert( "Handler for .change() called." );
    });
});

See working demo : View Demo Here 查看工作演示: 在此处查看演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM