如果提交,这将有效 - 您不需要添加查询字符串 - 如果它是 <a href="...,那么您将需要 url 的完整查询字符串:
<form action="php/test.htm" method="get">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" required/>
</td>
<input type="submit" name="submit" value="Submit" />
</form>
这给了我my url + /php/test.htm?codecosult=ghrth&submit=Submit
ghrth 是我输入的内容。
如果您使用脚本提交它,请关闭查询字符串并让“GET”方法处理它 - 此处的脚本位于头部。
<script language="javascript">function submit_this(){this.form.submit();}</script>
</head>
<body>
<form name="form" id="form" action="php/test.htm" method="GET">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" id="codecosult" required/>
</td>
<div onClick="submit_this();">Submit</div>
这给了我my url + test.htm?codecosult=dfthwrth
dfthwrth 是我输入的内容。
这也有效,尽管每次按下按键时,此处的 keypress 事件都会修改 <a href="... 的 href(可能不适用于所有浏览器):
<input type="text" name="codecosult" onKeyPress="ahreff.href='php/test.htm?'+this.value;" required/>
<a href="#" id="ahreff">Click Here</a>
这可能很有趣 - 下拉列表将以相同的方式传递其值:
dropdown menu doesn't function - 现在会了!