html5怎么通过输入指定文字跳转指定界面
就是用户输入指定文字,跳转指定界面
如:
用户在输入框输入bing,跳转到https://bing.com/
用户在输入框输入google,跳转到https://google.com/
html5怎么通过输入指定文字跳转指定界面
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-sinJack 2023-08-18 19:46关注
<html> <head> <meta charset="UTF-8"> <title>跳转</title> </head> <body> <form> <label for="search">输入关键字:</label> <input type="text" id="search" name="search"> <button type="submit">搜索</button> </form> </body> <script language="javascript"> const form = document.querySelector('form'); form.addEventListener('submit', function(event) { event.preventDefault(); const searchInput = document.querySelector('#search'); window.location.href = 'https://'+searchInput.value+'.com/'; }); </script> </html>本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报 编辑记录解决 1无用