表单重定向提交不工作,为什么

Form redirect on submit not working, why?

本文关键字:为什么 工作 重定向 提交 表单      更新时间:2023-09-26

我有以下代码在我的搜索表单:

<form name="search" method="get" action="www.test.gr" enctype="multipart/form-data" 
     onsubmit="window.location.href='www.test.gr/search/document.getElementById('location').value';  
             return false;">

但它不起作用。也许document.getElementById里面的报价是错误的。有人能帮忙吗?

您应该将字符串与对象值连接起来。在您的示例中,document.getElementById('location').value语句被解释为字符串的一部分。

<form name="search" method="get" action="www.test.gr" enctype="multipart/form-data" onsubmit="window.location.href = 'www.test.gr/search/' + document.getElementById('location').value;  return false;">