justhrun

jqueryregex2

Jul 19th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head><title>Bla Bla Bla</title>
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  5. <script>
  6. $(document).ready(function(){
  7. $('#pencet').on('click', function(){
  8. var arrText = $('#mytxtarea').val().trim().split('\n');
  9. var newText = '';
  10. if(arrText.length==2) {
  11. newText = arrText.join('');
  12. } else {
  13. $.each(arrText, function(i,text) {
  14. if(text.length < 1 || text == "\r\n" || text == "\n" || text == "\r" || text == "\n\r") {
  15. return true;
  16. }
  17. newText+= text+'\n';
  18. });
  19. }
  20. $('#newarea').val(newText);
  21. });
  22. });
  23. </script>
  24. </head>
  25. <body>
  26. <center>
  27. <textarea name="mytxtarea" id="mytxtarea" rows=7 cols=33>This is a sample text</textarea>
  28. <br><button id=pencet>test</button><br><br>
  29. <textarea id="newarea" rows=7 cols=33 style='border:none;'></textarea>
  30. <center>
  31. </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment