按Enter键时如何使用Jquery Mulitple Autocomplete在文本区域中添加新行?

时间:2015-06-04 07:33:57

标签: jquery autocomplete

我正在使用它,但在textarea而不是输入字段

https://jqueryui.com/autocomplete/#multiple

我的JQuery代码在

之下
<script>
$(function() {
var availableTags = [
  "Headache",
  "Headache all the time",
  "Increase in the morning",
  "Headache with effect on vision",
  "only episodic Headache with Vomiting",
  "one sided Headache"
];


function split( val ) {
  return val.split( / \s*/ );
}
function extractLast( term ) {
  return split( term ).pop();
}

$( ".tags" )
  // 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({
    minLength: 0,
    source: function( request, response ) {
      // delegate back to autocomplete, but extract the last term
      response( $.ui.autocomplete.filter(
        availableTags, 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>

目前textarea就是这样展示的 http://prntscr.com/7cxvgb 而我想要的是什么 http://prntscr.com/7cxvvd 意思是每当我按下文本区域输入时,它应该添加新行。

当前输出 http://prntscr.com/7cxweu 但是当我按下textarea中的输入时,我希望在新行中。 提前谢谢。

0 个答案:

没有答案