2011-12-06 48 views
2

我需要建立一个形式把用户输入并生成一个查询字符串,然后加载该URL采取HTML的输入,并建立一个查询字符串

例如

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

有没有一种办法这只使用HTML,或者这是否需要JavaScript?最简单的方法来做任何指针表示赞赏。

回答

9

只需设置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="/"> 

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> 
+0

啊哈!我知道这比我想象的要简单。非常感谢。 – user547794

相关问题