将表单值附加到操作 url - 动态
Appending form value to action url - Dynamic
我有这样的表格:
<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">
<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>
我有这样的表格:
<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">
<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>