【问题标题】:HTML form not changing URL as expectedHTML 表单未按预期更改 URL
【发布时间】:2016-03-02 22:33:42
【问题描述】:

我的项目中有一个问题,我还不能解决。 我正在使用 MySQL - PHP,一切正常,但是当我尝试使用下面的表单打开“php/consult.php?consult=add”时。

<form action="php/consult.php?consult=add" method="get">
        <td>Instruccion SQL:</td>
        <td>
        <input type="text" name="codecosult" required/>
        </td>
</form>

我的浏览器没有将 URL 更改为“php/consult.php?consult=add”。相反,它只显示“php/consult.php”,我做错了什么? 感谢您的回答和您的时间,对不起我的英语(不太好 xD)。

【问题讨论】:

    标签: php html


    【解决方案1】:

    如果提交,这将有效 - 您不需要添加查询字符串 - 如果它是 &lt;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&amp;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 事件都会修改 &lt;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 - 现在会了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-09
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多