javascript - 你能做一个可变的href,而不是一个按钮,只有一个文本框
问题描述
我正在制作一个搜索引擎,我想知道您是否可以制作一个可更改的href
,而不是button
只有一个textbox
. 这就是我所拥有的:所以我可以使用一种不同的方式让我能够按 Enter 键而不是让我知道
<input id="input" type="url"></input>
<button id="link button"><a id="link" style="text-decoration: none; color: inherit;" href="" TARGET="_BLANK">enter</a></button>
<script src="script.js">
var linkButton = document.getElementById("link button")
linkButton.onclick = function(){
var input = document.getElementById("input").value
document.getElementById("link").setAttribute("href", "http://"+input)
}
</script>
解决方案
另一种选择是使用表格
function myfunction(){
var inputbox = document.getElementById('inputval');
document.querySelector('#check').innerText = inputbox.value;
window.open('http://'+inputbox.value);
}
<form onsubmit="myfunction();return false;">
<input name="value" id="inputval"/>
<p id="check"></p>
</form>
推荐阅读
- r - 有没有办法从 shinyapp.io 链接找到 R 代码?
- c++ - xcode 13 无法编译某些函数 c++
- python - 使用类中的函数关闭弹出窗口(kivy)
- sql - 有没有办法在忽略 Spring Boot 中的外键检查的同时截断表?
- anylogic - 步行图书馆的资源可用性
- node.js - 为什么我的服务器在尝试安装 SCSS 后停止工作?
- c - 由于使用指向结构的指针的函数,for 循环意外中断
- python-3.x - 为什么我必须在 SBS scikit-learn 中选择特征数量?
- typescript - 打字稿:是否可以确保键和内部值是相同的字符串?
- charts - Tradingview 添加带有工具提示或其他标志的绿色或红色箭头