2016-07-25 59 views
-1

我有一個asp texbox,它具有佔位符和jquery自動完成功能。兩個工作正常,但在IE8佔位符無法正常工作。爲了使它工作,我在jquery中放置佔位符的水印,但隨後顯示水印,但自動完成不起作用。所有的問題是在IE8:asp文本框佔位符和自動完成不在IE8中一起工作

<asp:TextBox ID="txtLocation" runat="server" CssClass="frmhometxtLocation" placeholder="Locations" 
          onblur="Javascript:FormatLocation();"></asp:TextBox> 


     $("#txtLocation") 
     // don't navigate away from the field on tab when selecting an item 
      .bind("keydown", function (event) { 
       if (event.keyCode === $.ui.keyCode.TAB && 
       $(this).autocomplete("instance").menu.active) { 
        event.preventDefault(); 
       } 
      }) 

      .autocomplete({ 
       delay: 0, 
       minLength: 1, 
       source: function (request, response) { 
        // delegate back to autocomplete, but extract the last term 
        response($.ui.autocomplete.filter(
       locations, extractLast(request.term))); 
       }, 
       focus: function() { 
        // prevent value inserted on focus 
        return false; 
       }, 
       select: function (event, ui) { 
        var terms = split(this.value); 
        // remove the current input 
        terms.pop(); 
        // add the selected item 
        terms.push(ui.item.value); 
        // add placeholder to get the comma-and-space at the end 
        terms.push(""); 
        this.value = terms.join(", "); 
        return false; 
       } 
      }); 
    }); 
+0

請描述你得到的錯誤。它並不少見的JavaScript代碼不能與其他瀏覽器一起工作一些時間,並需要一些小的改變。你有沒有包含與IE8一起工作的正確庫? – Aristos

+0

使用水印時出現的錯誤是Microsoft JScript運行時錯誤:對象不支持此屬性或方法 – Anurag

回答

0

我在這裏做了一個錯誤,不包括Watermark.min.js。使用工具提示進行水印。現在它工作完美。這裏是正確的代碼:

<script src="Scripts/jquery-1.10.2.js" type="text/javascript"></script> 
<script src="Scripts/jquery-ui1.11.4.js" type="text/javascript"></script> 
<script src="Scripts/Watermark.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(function() { 
     var locations = ["Anywhere", "Gurgaon", "Delhi", "Noida","Chennai"]; 
     function split(val) { 
      return val.split(/,\s*/); 
     } 
     function extractLast(term) { 
      return split(term).pop(); 
     } 

     $("#txtLocation") 
     // don't navigate away from the field on tab when selecting an item 
     .WaterMark(
     { 

     }) 
      .bind("keydown", function (event) { 
       if (event.keyCode === $.ui.keyCode.TAB && 
       $(this).autocomplete("instance").menu.active) { 
        event.preventDefault(); 
       } 
      }) 

      .autocomplete({ 
       delay: 0, 
       minLength: 1, 
       source: function (request, response) { 
        // delegate back to autocomplete, but extract the last 
        response($.ui.autocomplete.filter(
       locations, extractLast(request.term))); 
       }, 
       focus: function() { 
        // prevent value inserted on focus 
        return false; 
       }, 
       select: function (event, ui) { 
        var terms = split(this.value); 
        // remove the current input 
        terms.pop(); 
        // add the selected item 
        terms.push(ui.item.value); 
        // add placeholder to get the comma-and-space at the end 
        terms.push(""); 
        this.value = terms.join(", "); 
        return false; 
       } 
      }); 
    }); 
}); 
</script> 
<asp:TextBox ID="txtLocation" runat="server" CssClass="frmhometxtLocation" placeholder="Locations" ToolTip="Locations" 
          onblur="Javascript:FormatLocation();"></asp:TextBox>