2015-11-05 32 views
0

我想在用戶將某個術語輸入到textarea中時更改url-hash部分。 一種文字底部。 我的背景:藝術學校。所以幾乎沒有腳本技能。 而不是所有的JavaScript。 ,但花了很多時間甚至在這裏。用戶輸入文本作爲更改散列的按鈕

是我到目前爲止已經完成:

<html> 
<body> 
<input type="textarea" placeholder="text buttons... " id="search"> 
<script src="jquery-1.11.3.js"></script> 

<div class="text-buttons" type="submit" style="visibility: hidden"> 
    <div>info</div> 
    <div>essay</div> 
    <div>back</div> 
</div> 

<script> 
$('#search').keyup(function(){ 
    var searchTerm = $(this).val(); //user inputted 
    $(".text-buttons div").each(function(){ //loop through the list 
     if($(this).text().match(searchTerm)){ //check if list item contains the search term 
      term = $(this)//store the matched term in a variable 
      } 
       if (term === info)//check if the term is «info». 
        location.hash = "part2" //change the anchor part 
        window.onhashchange = function(); //calls he hashchange 
    }); 
}); 

</script> 
</body> 
</html> 

只是試圖改變這種代碼: an answer to another question on stackoverflow

回答

0

這會幫助你:

<input type="textarea" placeholder="text buttons... " id="search"> 

<div class="text-buttons" style="visibility: hidden"> 
    <div>info</div> 
    <div>essay</div> 
    <div>back</div> 
</div> 
<script> 
    $(function() { 
     $('#search').keyup(function() { 
      var searchTerm = $(this).val(); //user inputted 
      var term = ''; 
      $(".text-buttons div").each(function() { //loop through the list 
       if ($(this).text().match(searchTerm)) { //check if list item contains the search term 
        term = $(this).text();//store the matched term in a variable 
       } 
      }); 
      if (term === 'info')//check if the term is «info». 
       window.location.hash = "part2" //change the anchor part 
      window.onhashchange = function() { 
      }; //calls he hashchange 
     }); 
    }); 

</script>