jQuery each line in textarea

后端 未结 4 1610
别跟我提以往
别跟我提以往 2021-02-20 12:17

html



jquery

4条回答
  •  心在旅途
    2021-02-20 12:53

    You're not dealing with "this" properly. Try the following:

    $('button').click(function(){
      var arrayOfLines = $('#gps').val().split('\n');
      $.each(arrayOfLines, function(index, item) {
        console.log(this);
      });
    });
    

    Note that the "this" variable in the inner function starts with the newline, I believe. But this should get you on the right track.

提交回复
热议问题