多个文本框上的jQuery keyup不适用于IE11

时间:2014-11-14 15:43:21

标签: javascript jquery keyup

我有多个文本框,并在每个文本框上调用jquery keyup工作 在mozilla firefox和chrome上很好。在Internet Explorer中

它对第一个文本框的工作正常,它应该是完美的工作,但其他文本框不能正常工作,我的意思是他们的密钥不是调用。 。我的代码是: -

我有多个文本框,并在每个文本框上调用jquery keyup工作 在mozilla firefox和chrome上很好。在Internet Explorer中

它对第一个文本框的工作正常,它应该是完美的工作,但其他文本框不能正常工作,我的意思是他们的密钥不是调用。 。我的代码是: -

    <script type="text/javascript">
    $(function(){
    $(".search").keyup(function() 
    { 

    var searchid = $(this).val();
    var idloc=document.getElementById("state").value;

    var type='p_school';
    var dataString = 'locality='+ searchid+'&id='+ idloc+'&type='+ type;

    if(searchid!='')
    {
        $.ajax({
        type: "POST",
        url: "loaddata.php",
        data: dataString,
        cache: false,
        success: function(html)
        {
        $("#result").html(html).show();
        }
        });
    }return false;    
    });

    jQuery("#result").on("click", ".show", function() {
        var $name = $(this).find(".name").text();
        var $id = $(this).find(".pid").text();
        var type='state';
        var pid='pid='+$id+'&type='+ type;
        $.ajax({
        type: "POST",
        url: "load_state.php",
        data: pid,
        cache: false,
        success: function(html)
        {
        //alert (html);
        $('#p_school').show();
        $('#p_school').html(html);
        $('#p_school_old').hide();
        }
        });
        $("#searchid").val($name);
        }); 

        jQuery(document).on("click", function(e) { 
        var $clicked = $(e.target);
        if (! $clicked.hasClass("search")){
        jQuery("#result").fadeOut(); 
        }
    });


    if(searchid=='')
    {
    $('#searchid').click(function(){
        jQuery("#result").fadeIn();
    }); }
    });

    $(function(){
    $(".search1").keyup(function() 
    { 
    alert ("hello second textbox");
    var searchid1 = $(this).val();
    var idloc1=document.getElementById("state1").value;
    var type1='s_school';
    var dataString1 = 'locality1='+ searchid1+'&id1='+ idloc1+'&type1='+ type1;


    if(searchid1!='')
    { 
        $.ajax({
        type: "POST",
        url: "loaddata.php",
        data: dataString1,
        cache: false,
        success: function(html)
        {
        $("#result1").html(html).show();
        }
        });
    }return false;    
    });

    jQuery("#result1").on("click", ".show1", function() { 
        var $name = $(this).find(".name1").text();
        var $id = $(this).find(".sid").text();
        //var pid='pid='+ $id.+'&type='+ type;
        var type='s_state'; 
        var pid='pid='+$id+'&type='+ type;
        $.ajax({
        type: "POST",
        url: "load_state.php",
        data: pid,
        cache: false,
        success: function(html)
        {
        //alert (html);
        $('#s_school').show();
        $('#s_school').html(html);
        $('#s_school_old').hide();
        }
        }); 

        $("#searchid1").val($name);
        //alert ("Danstring");

        });

        jQuery(document).on("click", function(e) { 
        var $clicked = $(e.target);
        if (! $clicked.hasClass("search_ss")){
        jQuery("#result1").fadeOut(); 
        }
    });

    if(searchid1=='')

    {
    $('#searchid1').click(function(){
        jQuery("#result1").fadeIn();
    });  }
    });


    </script>

//HTML Code

     HTML are below:-

    <input type="text" placeholder="Primary School" name="primary[]" autocomplete="off" class="search" id="searchid" style="margin-top: 7px; border: 1px solid #7B9E94; min-height: 29px;">

    <input type="text" placeholder="Secondary School" name="secondary[]" autocomplete="off" class="search1"  id="searchid1"  style="margin-top: 7px; border: 1px solid #7B9E94; min-height: 29px;">


    Thanks

1 个答案:

答案 0 :(得分:1)

由于您的输入元素具有不同的类名,请尝试更改此行:

$(".search").keyup(function()

到此:

$(".search, .search_ss").keyup(function()