我需要构建一个表单获取用户输入并构建一个查询字符串,然后加载该URL
例如
<form id="form1" name="form1" method="post" action="">
<p>
<label>INPUT1
<input type="text" name="INPUT1" id="INPUT1" />
</label>
</p>
<p>
<label>INPUT2
<input type="text" name="INPUT2" id="INPUT2" />
</label>
</p>
<p>
<label>
<input type="submit" name="loadURL" id="loadURL" value="Submit" />
</label>
<br />
</p>
</form>
http://website.com&model=<INPUT1>&cathegory=<INPUT2>
Run Code Online (Sandbox Code Playgroud)
有没有办法只使用HTML,或者这需要javascript?任何关于最简单方法的指针都表示赞赏.
只需设置action="/some/form/processor"和method="get"(而不是发布),表单中的字段将作为查询字符串发送.
为了让您的例子http://website.com&model=<INPUT1>&cathegory=<INPUT2>,你将有
<form id="form1" name="form1" method="get" action="http://website.com">
<!-- or, more simply, since the website _is_ website.com -->
<form id="form1" name="form1" method="get" action="/">
Run Code Online (Sandbox Code Playgroud)
该input 名称用作参数,让你完整的形式将
<form id="form1" name="form1" method="get" action="/">
<p>
<label>INPUT1
<input type="text" name="model" id="INPUT1" />
</label>
</p>
<p>
<label>INPUT2
<input type="text" name="cathegory" id="INPUT2" />
</label>
</p>
<p>
<label>
<input type="submit" name="loadURL" id="loadURL" value="Submit" />
</label>
<br />
</p>
</form>
Run Code Online (Sandbox Code Playgroud)