2017-02-20 54 views
-5

我有一個簡介形式,就像填寫我的生物數據或信息。我填寫了不同的段落和數字。只不過輸出將顯示一個段落如何填寫表格數據或數字,如何去下一段?

<div class="col-lg-12"> 
    <div class="form-group"> 
     <textarea autocomplete="off" rows="4" class="form-control" 
      name="introduction" type="text" 
     ></textarea> 

    </div> 
</div> 

我試圖讓輸出像

1 
    2 
    3 
    1).One 
    2).Two 
    3).Three 

但在我的形式,如果我填的數據或數字輸出顯示像

1 2 3 1).One 2). Two 3).Three 
+1

爲什麼不使用TAB鍵 - KISS? https://en.wikipedia.org/wiki/KISS_principle – lin

+0

這是一個輸入密鑰的使用 - https://en.wikipedia.org/wiki/Enter_key – lin

+0

你有什麼嘗試?請添加一些代碼。你知道HTML屬性'tabindex'? https://www.w3schools.com/Tags/att_global_tabindex.asp – lin

回答

1

這是一個CSS問題,而不是JavaScript問題。 HTML默認會摺疊空白 - 這包括忽略換行符。

white-space: pre-wrap添加到輸出格。

以下是示例代碼:

{ 
white-space: pre-wrap 
} 
0

http://jsfiddle.net/z02L5gbx/198/

.directive('nextOnEnter', function() { 
    return { 
     restrict: 'A', 
     link: function ($scope, selem, attrs) { 
      selem.bind('keydown', function (e) { 
       var code = e.keyCode || e.which; 
       if (code === 13) { 
        e.preventDefault(); 
        var pageElems = document.querySelectorAll('input, select, textarea'), 
         elem = e.srcElement 
         focusNext = false, 
         len = pageElems.length; 
        for (var i = 0; i < len; i++) { 
         var pe = pageElems[i]; 
         if (focusNext) { 
          if (pe.style.display !== 'none') { 
           pe.focus(); 
           break; 
          } 
         } else if (pe === e.srcElement) { 
          focusNext = true; 
         } 
        } 
       } 
      }); 
     } 
    } 
}) 

來源:如果你使用jQuery

在JavaScript 試試這個

這將替換所有(通過名稱和/或ID號和您的textarea)angularjs move focus to next control on enter

+0

太棒了,它也可以用TAB作爲自動對焦功能。這將工作,直到用戶必須填寫一個textarea,並嘗試在文本中打破。 – lin

+3

您應該將其標記爲重複項,而不是複製/粘貼現有​​答案。 – Mistalis

1

使用jQuery鍵盤事件

$(document).keydown(function (event) { 
     toCharacter(event.keyCode); 
}); 

function toCharacter(keyCode) { 

    // delta to convert num-pad key codes to QWERTY codes. 
    var numPadToKeyPadDelta = 48; 

    // if a numeric key on the num pad was pressed. 
    if (keyCode >= 96 && keyCode <= 105) { 
     keyCode = keyCode - numPadToKeyPadDelta; 
     return String.fromCharCode(keyCode); 
    } 

    if (keyCode == 106) 
     return "*"; 

    if (keyCode == 107) 
     return "+"; 

    if (keyCode == 109) 
     return "-"; 

    if (keyCode == 110) 
     return "."; 

    if (keyCode == 111) 
     return "/"; 

    // the 'Enter' key was pressed 
    if (keyCode == 13) 
     return "="; //TODO: you should change this to interpret the 'Enter' key as needed by your app. 

    return String.fromCharCode(keyCode); 
} 
相關問題