从单个文本框中分离值

需要一点帮助。

下面的脚本从文本框中选择值,并将其添加到URL并打开它。

例:

文字框值:

one
two
three
Four
Five
Six
Seven

Output URL: https://www.google.com/search?q=one+two+three+four+five+six+seven

我需要的帮助:

我希望根据分隔符将文本框值再次分为两个变量,例如逗号(脚本已经根据换行将文本框值分开),并将该值存储在两个不同的变量中。

例:

文字框值:

one,two
three,four
five,six

该值应基于','

例:

val1= one;
val2= two;

Output URL: https://www.google.com/search?q=val1+val2

这应该是一个循环,以便一旦执行了第一组值,它将移至下一个:

例:

val1= three;
val2= four;

Output URL: https://www.google.com/search?q=val1+val2

$(function() {
  $("#text1").click(function() {
    if ($('#textbox1').val() != '') {
      var search_container1 = $("#textbox1").val().split(" ");
      for (k = 0; k < search_container1.length; k++) {
        search_container1[k] = search_container1[k].replace(/\s/gi, "+");
      }
      var srcbox1 = "val1234";

      if (srcbox1 == "val1234") {
        var search_val1234 = "";
        for (var i = 0; i < search_container1.length; i++) {
          search_val1234 = search_container1[i]; {
            window.open("https://www.google.com/search?client=firefox-b-d&q=" + search_val1234 + "");
          }
        }

      }
    } else if ($('#textbox1').val() == '') {
      alert("Enter Keyword");
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">

  <div class="col-sm">
    <div class="card">
      <div class="card-body">
        <center><a>Deal IDs</a></center>
        <br>
        <textarea id="textbox1" cols="5" rows="7"></textarea><br>
        <center><br><button id="text1" class="btn btn-warning btn-block ">Submit</button></center>
      </div>
    </div>
  </div>
</div>
评论