Javascript how to split newline

后端 未结 12 1918
一整个雨季
一整个雨季 2020-11-28 06:48

I\'m using jquery, and I have a textarea. When I submit by my button I will alert each text separated by newline. How to split my text when there is a newline?



        
12条回答
  •  失恋的感觉
    2020-11-28 07:37

    The problem is that when you initialize ks, the value hasn't been set.

    You need to fetch the value when user submits the form. So you need to initialize the ks inside the callback function

    (function($){
       $(document).ready(function(){
          $('#data').submit(function(e){
          //Here it will fetch the value of #keywords
             var ks = $('#keywords').val().split("\n");
             ...
          });
       });
    })(jQuery);
    

提交回复
热议问题