搜索字词到网址

问题描述 投票:0回答:2

我正在努力使搜索引擎成为“比较者”。我的意思是我想创建一个本地网站,它需要一个搜索词,并使其成为一个可点击的搜索引擎URL(谷歌,bing,雅虎等)。我是从谷歌开始的。搜索词需要追求https://www.google.com/search?q=我不知道如何将userSearch添加到URL的末尾并将URL变为可点击的链接。我甚至不确定我是否正确收集了搜索词。

<!-- Enter search term -->
        <form>
          <fieldset>
            <legend></legend>
            <p>
              <label>Search Here! (please, no spaces)</label>
              <input type = "text"
                     id = "userSearch"
                     var = term
 />
            </p>

          </fieldset>
        </form>



<var> gURL = 'https://www.google.com/search?q=' + userSearch </var>


<script type="text/javascript">
    <var> searchTerm = "userSearch"; </var>
    <var> gURL = "https://www.google.com/search?q=" + 'searchTerm'; </var>

    document.getElementById("gURL").src = url;
</script>


<!-- Search URL results -->


        <h3>Results</h3>
        <fieldset>
        <h4 style="text-align:left;"><a href="https://www.google.com/search?q=">Google.com </a>

如果你能提供帮助,谢谢你。我很感激。

html var
2个回答
0
投票

我使用了一个按钮和Jquery - 但这是你想要做的吗?

<html>
<head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</style>
<script type="text/javascript">
$(document).ready(function() {
  $('#userSearch').click(function() {
    var fromForm =  "<br>" + '<a href="https://www.google.com/search?q="' + 
        $('#searchField').val() + ">" + 'https://www.google.com/search?q="' +$('#searchField').val() + '</a>';

    $('#outPut').append(fromForm);

  });

});     
</script>
</head>
<body>


<br>
<!-- Enter search term -->
<form>
          <fieldset>
            <legend></legend>

                 <label>Search Here! (please, no spaces)</label> <input type='text' id='searchField' placeholder="Search">
</fieldset>
</form>
                    <button id='userSearch'>Search</button>

<br>
<div id='outPut'>
    </div>

0
投票

我能够使用多个指南使用一些不同的代码使我的比较器,但我非常感谢您的反馈。我将我的代码放在Weebly网站(Click here)上,我的目标是使它成为一个工具,可以很容易地从不同的引擎搜索。它主要是供个人使用,但我设置了其他人可以发现它有用和有用的地方。

我用过这段代码:

    <!-- Enter search term -->
<div>
<input name="searchTxt" type="text" maxlength="512" id="searchTxt" class="searchField" float: center; display: block;/>
</div>

<script type="text/javascript">
        //creates a listener for when you press a key
        window.onkeyup = keyup;

        //creates a global Javascript variable
        var inputTextValue;

        function keyup(e) {
          //setting your input text to the global Javascript Variable for every key press
          inputTextValue = e.target.value;

          //listens for you to press the ENTER key, at which point your web address will change to the one you have input in the search box
          if (e.keyCode == 13) {
            window.location = "https://www.google.com/search?q=" + inputTextValue;
          }
        }
</script>

谢谢你所有人的帮助,我一定会继续学习。

© www.soinside.com 2019 - 2024. All rights reserved.