由于我对 JavaScript 不是很熟悉,所以我需要一些帮助。
我有一个简单的表单,其中包含 1 个标题行、1 个搜索按钮、1 个描述字段和提交按钮。
<form action="test_form.php" method="get" id="test_form1">
Überschrift: <input name="label" id="label" type="text" /> <input name="google" type="button" value="google" /><br />
Beschreibung: <textarea id="description" name="description" rows="5" cols="33">Beschreibung eingeben</textarea><br />
</form>
<button type="submit" form="test_form1" value="Submit">Eintragen</button>
如果我在标题行中输入内容并单击 google 按钮,Google 页面应在新选项卡中打开,标题行中的文本应作为搜索参数自动附加到链接中。
例如,在标题行“动画图像”中,当您单击 Google 按钮时,应打开一个带有 URL“https://www.google.com/search?q=animated+Images”的新标签页。
如果它没有出现在标题中,当您点击 Google 时,Google 页面应该会在新标签页(“https://www.google.com”)中打开。
整个过程应该在不提交实际表格的情况下发生。
您可以做的是在有人单击搜索按钮时调用 search() 函数,您可以使用 window.open() 函数打开带有查询参数的新选项卡
<script>
function search(){
let string = document.getElementById("label").value;
window.open("https://www.google.com/search?q="+string);
}
</script>
<input type=
<button onclick="search()">Search</button>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句