@Backer 2023-08-18 19:18 采纳率: 20%
浏览 12
已结题

html5怎么通过输入指定文字跳转指定界面

html5怎么通过输入指定文字跳转指定界面
就是用户输入指定文字,跳转指定界面
如:
用户在输入框输入bing,跳转到https://bing.com/
用户在输入框输入google,跳转到https://google.com/

  • 写回答

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条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月28日
  • 已采纳回答 8月22日
  • 创建了问题 8月18日