jQuery change() on <select> and firefox

后端 未结 5 1772
孤城傲影
孤城傲影 2020-12-06 05:04

I have a dropdown that triggers an ajax call when its changed:

$(\'.travel-to\').change(function(){  
    $.ajax({
        type: \"GET\",
        url: \"/inc         


        
5条回答
  •  有刺的猬
    2020-12-06 05:19

    Maybe instead of using the change() event use the blur() event and check to see if the value changed?

    FYI, i have not tested this, just an idea that I had. and I am not sure if this is the desired effect because it would trigger on a lost of focus, but I am suggesting it as to keep the effect consistent across different browsers.

    var currentValue;
    
    $('.travel-to').blur(function(){
        var val = $(this).val();
        if (currentValue != val) {
            currentValue = val;
            $.ajax({
                type: "GET",
                url: "/inc/rates/rates-viewer.php",
                data: "shtech=y&c_name="+escape(currentValue),
                success: function(html){
                    $(".rates-viewer").html(html);
                    $(".rates-viewer tr.numbers td").css({ opacity: 0 }).fadeTo("slow",1);
                }
            });
        }
    });
    

提交回复
热议问题