【问题标题】:Appending form value to action url - Dynamic将表单值附加到操作 url - 动态
【发布时间】:2018-09-20 07:48:08
【问题描述】:

我有一个这样的表格:

<form action="http://localhost:8080/abc/def/gh" method="post">

我需要用当前主机名动态替换 localhost:8080

类似使用 - window.location.hostname

例如,如果触发代码的当前主机名的地址为 192.222.1.333:8080,则代码应动态转向:

<form action="http://192.222.1.333:8080/abc/def/gh" method="post">

【问题讨论】:

    标签: javascript html forms url-routing


    【解决方案1】:
    <html>
    <body>
        <form action="http://localhost:8080/abc/def/gh" id="action-form" method="post"></form>
    
        <script>
            var form = document.getElementById("action-form");
            form.action = form.action.replace("localhost:8080", window.location.hostname);
        </script>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2016-03-11
      • 1970-01-01
      • 2016-07-13
      • 2010-11-15
      • 1970-01-01
      • 2013-05-11
      • 2019-11-30
      • 2014-02-21
      相关资源
      最近更新 更多