我正在尝试使搜索引擎“比较”。我的意思是说,我正在尝试制作一个带有搜索词的本地网站,并将其变成可点击的搜索引擎URL(google,bing,yahoo等)。我从Google开始。搜索字词需要放在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>
如果可以帮助您,谢谢。我很感激。
答案 0 :(得分: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>
答案 1 :(得分: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>
谢谢大家的帮助,我一定会继续学习的。