2016-08-29 1 views
0

내가 어려움을당했습니다. 첫 번째 입력은 예 : xyz 일 수 있습니다.이 입력은 tagsinput에서 값을 가져 오는 것을 보여줍니다. 두 번째 입력은 알래스카 (예 : 선행 사용) 일 수 있습니다. 세 번째는 벨기에와 같이 결합하지만 버튼을 클릭하면 countrySelection 입력에서 값을 가져올 수 없습니다. 아이디어가 있으십니까?
미리 감사드립니다.태그 입력에서 선행 기입으로 값 검색

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- BootStrap --> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <!-- JQuery --> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    <!-- TagsInput --> 
    <link rel="stylesheet" href="http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.css"> 
    <script src="http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script> 
    <!-- Typeahead --> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js"></script> 
</head> 

<body> 
    <div class="container"> 

     <!-- Tagging section --> 
     <div id="Tagging" class="row"> 
      <div class="form-group"> 
       <div class="col-sm-2"> 
        <label for="userTags">Manual Tags:</label> 
       </div> 
       <div class="col-sm-10"> 
        <input type="text" id="userTags" data-role="tagsinput" class="form-control" /> 
        <button type="button" class="btn btn-success pull-right" 
          onclick="alert($('#userTags').tagsinput('items'));">Show Tags</button> 
       </div> 
      </div> 
     </div> 


     <!-- This typeahead works but is not 'tagged' --> 
     <div id="tagOne" class="row"> 
      <div class="form-group" id="exampleOne"> 
       <div class="col-sm-2"> 
        <label for="stateSelection">TypeAhead Only:</label> 
       </div> 
       <div class="col-sm-10"> 
        <input id="stateSelection" type="text" class="form-control typeahead" /> 
        <button type="button" class="btn btn-success pull-right" 
          onclick="alert($('#stateSelection').val());">Show Tags</button> 
       </div> 
      </div> 
     </div> 
     <script> 
      var states = ['Alabama', 'Alaska', 'Arizona']; 
      var myStates = new Bloodhound({ 
       datumTokenizer: Bloodhound.tokenizers.whitespace, 
       queryTokenizer: Bloodhound.tokenizers.whitespace, 
       local: states 
      }); 
      myStates.initialize(); 

      $('#exampleOne .typeahead').typeahead({ 
       hint: true, 
       highlight: true, 
       minLength: 1 
      }, 
       { 
        name: 'states', 
        source: myStates 
       });    
     </script> 


     <!-- This typeahead works and is 'tagged' but cannot retrieve items --> 
     <div id="tagTwo" class="row"> 
      <div class="form-group"> 
       <div class="col-sm-2"> 
        <label for="countrySelection">TypeAhead with Tags:</label> 
       </div> 
       <div class="col-sm-10"> 
        <div id="exampleTwo"> 
         <input type="text" id="countrySelection" data-role="tagsinput" class="form-control" /> 
        </div> 
        <button type="button" class="btn btn-success pull-right" 
          onclick="alert($('#countrySelection').tagsinput('items'));">Show Tags</button> 
       </div> 
      </div> 
     </div> 
     <script> 
      var countries = ['Belgium', 'Finland', 'New Zealand']; 
      var myCountries = new Bloodhound({ 
       datumTokenizer: Bloodhound.tokenizers.whitespace, 
       queryTokenizer: Bloodhound.tokenizers.whitespace, 
       local: countries 
      }); 
      myCountries.initialize(); 

      $('#exampleTwo').tagsinput({ 
       typeaheadjs: ({ 
        hint: true, 
        highlight: true, 
        minLength: 1, 
        name: 'countries', 
        source: myCountries 
       }) 
      }); 
     </script> 

    </div> 
</body> 
</html> 

답변

0

잘못된 것으로 밝혀졌습니다. 해당 코드로 변경

alert($('#exampleTwo').tagsinput('items')) 

등 모두 양호합니다. 환호