【问题标题】:I want a input which has a button besides it我想要一个除此之外还有一个按钮的输入
【发布时间】:2021-09-11 14:54:45
【问题描述】:
我想要一个旁边有一个按钮的输入,每当我点击该按钮时,它都会将我带到一个位置(准确地说:“https://localhost:5000/message/to={{inputbyuser}} ") 其中 {{inputbyuser}} 是用户输入的输入。另外,因为我稍后将托管它,所以我不希望 localhost 出现,而是希望网页获得它自己的域。有办法吗?
我的 HTML sn-p:
<input type="text" placeholder="Enter the username to chat : " class="input-required"/><button type="submit" class="btn btn-lg"><i class="fas fa-paper-plane"></i></button>
是的,发送按钮是一个图标。
【问题讨论】:
标签:
html
forms
redirect
input
【解决方案1】:
是的!
首先,给按钮的 ID 为 submit_btn,输入字段的 ID 为 input_field,然后,在页面末尾添加一些 JavaScript:
document.getElementById("submit_btn").addEventListener("click", () => {
const input_value = document.getElementById("input_field").value;
window.location.href = `https://localhost:5000/message/to=${input_value}`;
});
我希望这会有所帮助!
【讨论】:
-
但是如果我将它放在网上,那么 href 会起作用吗?我正在寻找一些解决方案,应用程序可以通过它获取其域并向其发送请求。我不想写localhost:5000