IE10上的Jquery问题

时间:2015-09-28 16:09:56

标签: javascript jquery internet-explorer browser

以下jquery代码在最新版本的Chrome上运行良好,

在输入字段的焦点事件上,它应该使用ajax触发字段本身的自动完成以检索建议,但它在IE10上根本不起作用

控制台是空的......

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script>
  $(function() {

    function log( message ) {
      $( "<div>" ).text( message ).prependTo( "#log" );
      $( "#log" ).scrollTop( 0 );
    }

     $( "#myBut").click(function(){

     if($('#city').val() == "")
     return;

     log("selected: " + $("#city").val() );

     $('#city').val("");
     $('#city').blur("");

     });

    $( "#city" ).autocomplete({
      source: function( request, response ) {
        $.ajax({
          url: "http://localhost:8085/TestJsonArrayAJAX/MyServlet",
          dataType: "json",
          data: {
            q: request.term
          },
          success: function( data ) {

            alert("ciao");
            response( data );
          }
        });
      },
      minLength: 0,
      select: function( event, ui )
      {

          alert('ccc');

      },
      open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
      },
      close: function() {
        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
    }}).focus(function() {    alert("c"); 
            //Use the below line instead of triggering keydown
            $(this).data("uiAutocomplete").search($(this).val()) });
  });
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="city">Your city: </label>
  <input id="city">
  Powered by <a href="http://geonames.org">geonames.org</a>

</div>

<button name="subject" id="myBut" value="HTML">HTML</button>

<div class="ui-widget" style="margin-top:2em; font-family:Arial">
  Result:
  <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

IE上存在Access-Control-Allow-Origin的已知问题。这有帮助吗? document.body.scrollTop is always 0 in IE even when scrolling