简体   繁体   English

如何向该文件输入 go

[英]How can I make an input go to that file

I was wondering how it would be possible to take an HTML input and with javascript make it so that if the user enters 1.html in the input it will take them to the file 1.html? I was wondering how it would be possible to take an HTML input and with javascript make it so that if the user enters 1.html in the input it will take them to the file 1.html?

This is a rough illustration but should give you the general idea.这是一个粗略的说明,但应该给你一个大致的想法。 There's a lot you'd want to add to this but I figure you just want a starting point.您想添加很多内容,但我认为您只需要一个起点。

<form>
<input type='text' class='path'>
<input type='button' class='btn' value='Go!'>
</form>

<script>
    let btn = document.querySelector('.btn');
    let inputPath = document.querySelector('.path');
    
    // redirect to chosen path
    btn.addEventListener('click', function(){
        location.href = inputPath.value;
    });
</script>

You may also wish to consult the location object docs.您可能还希望查阅位置object 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM