duanliang1019 2014-10-21 01:15
浏览 56

为html表单添加额外的文本GET方法

When using the 'get' method for form,

<form action="domain.com" method="get">
    Surname: <input type="text" name="ABC"><br>
    Name: <input type="text" name="DFG"><br>
    <input type="submit" value="Submit">
</form>

the input will be sent to a page on the server called

domain.com/?ABC=surname&DFG=name

My question: how to edit the form to make it such that the input gets sent to a page called

domain.com/?ABC="surname"&DFG="name"

(notice the " " around the two inputs.

Please advice. Thanks!

  • 写回答

2条回答 默认 最新

  • douchuilai2355 2014-10-21 01:18
    关注

    I believe you are looking for the quotation mark character (U+0022) which is not allowed in plain text it must be encoded as %22.

    I did some javascript to add the doublequotation mark characters to your input from the user, and then it should submit the form action as before.

    <script type="text/javascript">
        beforeSubmit = function(){
              var abc = document.getElementById("ABC").value; 
              document.getElementById("ABC").value = "%22" + abc + "%22";
              var dfg = document.getElementById("DFG").value; 
              document.getElementById("DFG").value = "%22" + dfg + "%22"; //changes input field value
              document.getElementById("formid").submit(); //submits the form
        }
    </script>
    <form action="domain.com" method="get" id="formid">
        Surname: <input type="text" name="ABC" id="ABC"><br>
        Name: <input type="text" name="DFG" id="DFG"><br>
        <input type="button" value="Click" onclick="beforeSubmit();" />
    </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数