简体   繁体   English

Javascript 表单重定向(带变量)

[英]Javascript form redirect (with variable)

I need help getting started this may be tricky.我需要帮助开始这可能很棘手。

I want a javascript whereby it allows you to enter a variable.我想要一个 javascript,它允许你输入一个变量。 (For instance, a name)and for whatever name is entered, it redirects you to a page (based on the variable entered). (例如,名称)无论输入什么名称,它都会将您重定向到一个页面(基于输入的变量)。

The website would be pretty blank, and have the question.该网站将非常空白,并且有问题。

"What is your name?" “你叫什么名字?”

They'd enter their name, hit enter / submit - and it'll redirect them to the page, specific to their name.他们会输入他们的名字,按回车/提交 - 它会将他们重定向到特定于他们名字的页面。

Ideas?想法?

https://developer.mozilla.org/en-US/docs/Web/API/Document/location https://developer.mozilla.org/en-US/docs/Web/API/Document/location

JavaScript document.location property allows you to load another URL. JavaScript document.location属性允许您加载另一个 URL。

var name = 'John';
document.location = 'http://en.wikipedia.org/wiki/' + name;

This code sets name John to the local variable name .此代码将 name John设置为局部变量name Then it changes current document.location to http://en.wikipedia.org/wiki/John what leads to loading that URL in current tab of the browser (or window).然后它将当前document.location更改为http://en.wikipedia.org/wiki/John导致在浏览器(或窗口)的当前选项卡中加载该 URL。

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

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