开发者

JQuery change event on Select not firing IE8 Firefox 4.0.1

I know this question was asked before but I have the following simple code which is not working in IE / MOZILLA This is a simple script where I am trying to sort out a problem I had. see code below

<script type="text/javascript">
        $(docum开发者_Python百科ent).ready(function () {
            alert('hi');
        });

        $('.target').change(function () {
            alert('Handler for .change() called.');
        });
    </script>
    Index</h2>
<p>
<form action="/Review" method="post">        <select class="target">
            <option value="option1" selected="selected">Option 1</option>
            <option value="option2">Option 2</option>

        </select>


You need to move the .change binding up into the $(document).ready() or it will run before there is anything in the DOM that matches your .target selector:

$(document).ready(function() {
    alert('hi');
    $('.target').change(function () {
        alert('Handler for .change() called.');
    });
});


Try changing script like this.

$(document).ready(function () {
            alert('hi');
            $('.target').change(function () {
            alert('Handler for .change() called.');
           });
        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜