2013-07-22 42 views
0

我想在每行上自動完成,但它只在第一行上工作。自動完成在第一行上工作,但不能在新行上工作

autocomplere在第一行工作正常,但是當我添加新行時,自動完成不起作用。 我的代碼是在這裏 任何解決方案,請

這裏是HTML:

<table id="items"> 
    <thead> 
     <th>Items</th> 
    </thead> 
    <tbody> 
     <tr> 
      <td><input class="input3 item" name="name_1" type="text" value="" autocomplete="off"></td> 
     </tr> 
    </tbody> 
</table> 
    <br clear="both"> 
    <div id="addmore">Add new line</div> 

這裏是jQuery的:

// add new line 
$("#addmore").click(
    function() { 
     var someText = '<td><input class="input3 item" name="name_2" type="text" value=""></td>'; 
    var newDiv = $("<tr>").append(someText); 
    $('#items').append(newDiv); 
    } 
); 

// get autocomplete tags 
    var availableTags = [ 
     "ActionScript", 
     "AppleScript", 
     "Asp", 
     "BASIC", 
     "C", 
     "C++", 
     "Clojure", 
     "COBOL", 
     "ColdFusion", 
     "Erlang", 
     "Fortran", 
     "Groovy", 
     "Haskell", 
     "Java", 
     "JavaScript", 
     "Lisp", 
     "Perl", 
     "PHP", 
     "Python", 
     "Ruby", 
     "Scala", 
     "Scheme" 
    ]; 

    $(".item").autocomplete({ 
     source: availableTags, 
     minLength: 1, 
    }); 

你可以在JS中小提琴看到:http://jsfiddle.net/anosim/n3auc/4/ 請幫助我,謝謝Advance

+0

請幫助我, – anosim

回答

3

你的新行是動態添加的,所以我認爲你添加了一個新的行功能就需要這樣一些額外的代碼:

  $("#addmore").click(
       function() { 
       var someText = '<td><input class="input3 item" name="name_2" type="text" value=""> </td>'; 
       var newDiv = $("<tr>").append(someText); 
       $('#items').append(newDiv); 
       $(".item").autocomplete({ 
       source: availableTags, 
       minLength: 1, 
       }); 
      } 
      ); 

的jsfiddle:http://jsfiddle.net/n3auc/7/

+0

謝謝@gloria回答謝謝你對我來說是有幫助的。 – anosim

+0

請幫我在這個問題http://stackoverflow.com/questions/30637709/how-to-add-new-line-in-text-area-in-jquery-mulitple-autocomplete-when-pressing-e –

相關問題