Javascript-来自关键字“;某事“;谷歌搜索查询“;什么的&”;
Javascript - from keyword "something" to google search query "something."
任何人都能给出一些如何完成这项任务的指针吗?
这样做可能吗?或者我需要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演示
相关文章:
- 使用查询将对象数组发布到asp.net-mvc控制器操作的正确方法是什么
- 我对这个动态查询做错了什么
- Javascript-来自关键字“;某事“;谷歌搜索查询“;什么的&”;
- 什么是CSS媒体查询的JavaScript等价物
- 什么是用于断开变量可能包含“&”的查询字符串的正则表达式
- 拉斐尔气泡图查询(谁能告诉我这到底是什么图表?
- 专注于第一个表单元素,无论它是什么.j查询对话框
- 什么时候使用 ??和?作为 node-mysql 中的占位符,用于构建查询
- J查询每个函数后的值是什么意思
- 当前使用SuperAgent构造查询字符串的机制是什么
- Chrome/Firefox中双美元符号选择器查询功能的来源是什么
- 内爆查询是什么意思
- 在什么浏览器中查询字符串(防止缓存)工作
- 什么是new function(settings){..}(jQuery.查询|| {});javascript中的Me
- 在查询时“-”是什么意思?
- 在我的代码中,查询的含义是什么?
- 什么可能会打乱我用JavaScript构造的查询字符串参数
- 在HTML脚本标记中这个查询组件的目的是什么?
- 查询参数在webpack加载器中的用途是什么?
- 多实体搜索功能、Web API或手动查询应该使用什么?