Javascript-来自关键字“;某事“;谷歌搜索查询“;什么的&”;

Javascript - from keyword "something" to google search query "something."

本文关键字:查询 什么 搜索 某事 关键字 Javascript- 谷歌      更新时间:2024-01-16

任何人都能给出一些如何完成这项任务的指针吗?

这样做可能吗?或者我需要api吗?jquery或其他/api可以更容易地做到这一点吗?

"http://www.google.com/search?q="我想这应该在某个地方…

谢谢你的帮助。。

因此,它将把关键字suggestons从ubershing之类的东西转换为输出,你只需点击谷歌链接查询即可。。

HTML:

  <table>
    <tr>
      <td>
        <textarea cols="40" rows="3000" name="strings" id="strings"></textarea>
      </td>
      <td valign="top">
        <input type="button" value="Generer" onclick="getLongs();" />
      </td>
      <td>
        <textarea cols="40" rows="3000" id="long_strings"></textarea>
      </td>
    </tr>
  </table>

JavaScript:

  function getLongs() {
    var source_code = strings.value;
    var lines = source_code.split("'n");
    var total_lines = lines.length;
    var longs = 0;
    var longtail;
    for (i = 0; i < total_lines; i++) { 
      var words = lines[i].split(" ");
      if(words.length > 2) {
        document.getElementById("long_strings").value = document.getElementById("long_strings").value + lines[i] + ''n';
        longs++;
      }
    }
  }   

我改进了您的整个getLongs()函数(请参阅注释以了解解释):

function getLongs() {
    var source_code = document.getElementById('strings').value; //properly access the input in the text area
    var lines = source_code.split("'n");
    var total_lines = lines.length;
    var longs = 0;
    var longtail;
    for (i = 0; i < total_lines; i++) {
        var words = lines[i].split(" ");
        if (words.length > 2) {
            //creates an <a> node
            var node = document.createElement("A"); 
            //assigns your link to the 'href' attribute of the a node we created   
            //use 'join()' to concatenate the individual words with a '+' separator for the URL
            node.href = "http://www.google.com/search?q=" + words.join('+'); 
            //create a text node with the text value 
            var textnode = document.createTextNode(lines[i]); 
            //append the text node into our a node
            node.appendChild(textnode); 
            //append the a node to the #long_strings text area
            document.getElementById("long_strings").appendChild(node); 
            //create an add a <br> node to add separation between links in #long_strings
            var htmlbreak = document.createElement("BR");
            document.getElementById("long_strings").appendChild(htmlbreak);
            longs++;
        }
    }
}

更新的JSFIDDLE演示