获取textarea的第一行值

时间:2019-06-01 10:54:43

标签: javascript jquery

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
  <textarea id="tawktouser" rows="4" class="form-control"></textarea>
  <button type="button" id="add" class="btn green">Add</button>
</form>
<script>
  $(document).ready(function() {
    $("#add").click(function() {
      var tawktouser = $("#tawktouser").val();
      alert(tawktouser)
    });
  });
</script>

我无法以行方式获取textarea的值-例如第一行是姓名2nd电子邮件3rd是电话号码-像这样 名称:名称 电邮:abc@gmail.com 电话:11111

1 个答案:

答案 0 :(得分:0)

尝试

structure(list(type = c("human", "human", "human", "mouse", "mouse"
), status = c("living", "living", "dead", "living", "dead"), 
    count = c(36, 57, 43, 4, 8)), row.names = c(NA, -5L), class = c("tbl_df", 
"tbl", "data.frame"))

  var tawktouser = $("#tawktouser").val().split('\n');
  alert(tawktouser[0])