Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提交表单后如何重定向用户?_Javascript_Wordpress_Redirect_Elementor - Fatal编程技术网

Javascript 提交表单后如何重定向用户?

Javascript 提交表单后如何重定向用户?,javascript,wordpress,redirect,elementor,Javascript,Wordpress,Redirect,Elementor,目标: 在Elementor中提交表单后将用户重定向到不同页面。重定向将基于存储的javascript变量。我给了提交按钮一个名为submitbutt的ID 实施: 对于Elementor中的表单,我选择了提交后的操作到重定向。同样在重定向部分,我选择了到短代码选项,并参考了我的短代码[elementor template id=“1343”] 短代码 它是一个包含javascript的HTML,看起来像这样 <script type="text/javascript"> doc

目标: 在Elementor中提交表单后将用户重定向到不同页面。重定向将基于存储的javascript变量。我给了提交按钮一个名为
submitbutt
的ID

实施: 对于Elementor中的表单,我选择了提交后的
操作
重定向
。同样在
重定向
部分,我选择了
到短代码
选项,并参考了我的短代码
[elementor template id=“1343”]

短代码

它是一个包含javascript的HTML,看起来像这样

<script type="text/javascript">
  document.getElementById('submitbutt').onclick = function() {
if (localStorage.getItem('pagex') === 'page_1') {
 window.location = 'https://www.website.com/error/?1';
}
else if (localStorage.getItem('pagex') === 'page_2') {
  window.location = 'https://www.website.com/error/?2';
}
else {
 window.location = 'https://www.website.com/error/';
}
  };

</script>

document.getElementById('submitbutt')。onclick=function(){
if(localStorage.getItem('pagex')==“第1页”){
window.location=https://www.website.com/error/?1';
}
else if(localStorage.getItem('pagex')=='page_2'){
window.location=https://www.website.com/error/?2';
}
否则{
window.location=https://www.website.com/error/';
}
};
问题:用户点击提交按钮后,不会发生重定向

document.getElementById('submitbutt').addEventListener("click", function(event) {
event.preventDefault();
if (localStorage.getItem('pagex') === 'page_1') {
 window.location = 'https://www.website.com/error/?1';
}
else if (localStorage.getItem('pagex') === 'page_2') {
  window.location = 'https://www.website.com/error/?2';
}
else {
 window.location = 'https://www.website.com/error/';
}
});
使用带有按钮的事件处理程序

对于表单,要自定义按钮的行为,请使用