【问题标题】:Form Input will redirect to text entry表单输入将重定向到文本输入
【发布时间】:2018-07-26 01:50:29
【问题描述】:

是否可以在 HTML 中创建一个输入框,当用户输入一个单词时,它会重定向到 HTML 文件?例如,他们输入“Doctor”然后它会重定向到页面医生.html?

需要一些帮助,这是一个学校项目。谢谢:)

【问题讨论】:

  • 请在 google 上搜索 javascript, document.location.href 查找方法。
  • 是的。你有什么办法解决这个问题?
  • @Barmar 我的学校不教编程。对于该项目,我正在自己构建一个网站,我只是认为这将是一个很好的功能,可以包含在我正在构建的网站中。我一直在尝试对其进行研究,但找不到太多。

标签: javascript html css forms input


【解决方案1】:

给你

let button = document.getElementById('go');
button.addEventListener('click',function(){
  let word = document.getElementById('word');
      console.log( word.value +'.html' );
      //window.location.href = word.value +'.html';
      // uncomment above to go to /doctor.html
})
<input type="text" id="word" value="doctor">
<button id="go">go</button>

【讨论】:

  • 非常感谢!我试图做一些与这段代码非常相似的事情,但它不起作用。
猜你喜欢
  • 2011-02-22
  • 1970-01-01
  • 2011-08-04
  • 1970-01-01
  • 2019-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多