我遇到了一个问题。
我需要一个简单的输入表单来更改页面的相对 URL。假设我有 site.com/index
<form>
<p>
<label for="url"</label>
<input id="url" type="text" onchange="var a = document.createElement('a');
a.setAttribute('href', this.value); this.value = a.href; window.location.search="/a.href";" placeholder="Search">
<button type="submit">Submit</button>
</p> </form>
我哪里出错了?无论我在表单中输入什么,它都会将我重定向到 site.com/index?
也许我弄错了,这只能在后端处理。
提前致谢。
最佳答案
尝试以下操作
<form>
<p>
<label for="url"</label>
<input id="url" type="text" onchange="window.location='/'+this.value;" placeholder="Search">
<button type="submit">Submit</button>
</p> </form>
关于javascript - 输入表单以更改 javascript 中的相对 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40095564/