窗口.打开窗体.操作



试图用window.open打开这个脚本,有什么想法吗?

<script type="text/javascript">
function get_action(form) {
form.action = 'http://'+document.getElementById("address").value;)
}
</script>

我需要能够以某种方式把它放在";form.action=";

该函数应该是更改它的正确方法,但是您应该在表单提交后运行代码

window.onload = function () {
const form = document.querySelector("#myForm") // finds element with id of form
form.addEventListener("submit", function (e) {
e.preventDefault() // Stops the form from redirecting
form.action = `http://${document.getElementById("address").value}`
form.submit()
})
}

如果您希望它只在选项卡中打开而不提交任何表单数据,您可以使用window.open()

window.onload = function () {
const form = document.querySelector("#myForm") // finds element with id of form
form.addEventListener("submit", function (e) {
e.preventDefault() // Stops the form from redirecting
let url = `http://${document.getElementById("address").value}`
window.open(url)
})
}

如果您希望它在新窗口中打开,请将window.open(url)更改为window.open(url, "_blank", "location = yes")

最新更新