简体   繁体   English

jQuery .change不在IE中触发,但在FFOX中工作

[英]jquery .change not firing in IE but working in FFOX

I have the following HTML: 我有以下HTML:

<form method="post" action="#" name="dialog_head" id="dialog_head" class="jqtransform">   
    <ul>
        <li class="pdf">
            <a title="This PDF document opens in a new window" target="_blank" href="#">Save as PDF</a>
        </li>
        <li class="print">
            <a target="_blank" href="#">Print Price Report</a>
        </li> 
        <li>
            <label for="dialog_select">Select Price Report:</label>
            <select name="dialog_select" id="dialog_select"><option value="PriceReport/13415939">23 April 2010</option>
<option value="PriceReport/13415510">16 April 2010</option>
<option value="PriceReport/13415009">09 April 2010</option>
<option value="PriceReport/13414608">02 April 2010</option>
</select>
        </li>   
    </ul>
</form>

With the following jqQuery event listener attached to the select: 将以下jqQuery事件侦听器附加到select:

   $('select#dialog_select').live('change', function() {
        alert("foo");

        //set the select value
        var $optionVal = $(this).val();

        if ($optionVal != '') {

            // remove testing class for when new report has been requested
            $('#cboxLoadedContent > div').addClass('dialog_loading').removeClass('dialog_loaded');

            // call the price report and replace current price report
            $.ajax({
                type: 'GET',
                url: $optionVal,
                dataType: 'html',
                cache: true,
                success: function(data) {

                    var $findData = $(data).find('.Section1');

                    $('.Section1').fadeOut('fast', function() {

                        $('.Section1').replaceWith($findData).fadeIn('fast');

                        $('.Section1, .Section1 table').css({
                            'width': '95%',
                            'margin': 'auto'
                        });

                        // testing class for when report has been successfully loaded
                        $('#cboxLoadedContent > div').removeClass('dialog_loading').addClass('dialog_loaded');

                    });
                },

                error: function(xhr, ajaxOptions, thrownError) {
                    // testing class for load error
                    $('#cboxLoadedContent > div').removeClass('dialog_loading dialog_loaded').addClass('dialog_load_failure');
                    alert(xhr.status);
                    alert(thrownError);
                }

            });
        }

    });

This works in FFOX but not in IE7 and i don't know why??? 这在FFOX中有效,但在IE7中无效,我不知道为什么???

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

should do the trick. 应该可以。

There's no point in prepending your id with "select" by the way. 顺便说一句,在您的ID前面加上“ select”是没有意义的。 The only thing it could do is slow down jquery by making it isolate your select tags. 它唯一能做的就是通过隔离选择标记来减慢jquery的速度。 Id is always fastest. id总是最快的。

EDIT - as Sadat mentioned, this code should be wrapped in at least a 编辑-如萨达特所说,此代码至少应包装在

$(document).ready(function(){ ... }); 

if it isn't already. 如果还没有。

Try like- 尝试-

$(
  //do your all job here
   $('select#dialog_select').live('change', function() {
   ....
   ....
   )

);

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

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