繁体   English   中英

Wordpress联系表格7重定向单选按钮值不起作用

[英]Wordpress Contact Form 7 Redirect on radio button value not working

我过去5个小时一直在研究基于值的联系表7重定向。 我无法解释为什么我的代码不起作用。 谁能看到问题?

联系表格单选按钮

[radio radio-935 id:rating label_first "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"]

其他设置

on_sent_ok: " if (document.getElementById('rating').value=='9') {location.replace('http://www.google.com')} else { location.replace('http://www.msn.com/') } "

当我选择单选按钮9时,我将重定向到msn(else参数)。 所有其他值也都转到MSN(至少该部分是正确的)。 我尝试将其他设置更改为三等号===,但这无济于事。 我还尝试过在单选按钮中的每个值之后添加一个管道(|)。 那也不起作用。

看一下生成的HTML,您将知道为什么代码无法按预期工作。 有2个选项

艰难的道路

在外部JS文件中定义一个函数,该文件通过单选按钮进行迭代

function getRating(radioName) {
  var ratings = document.getElementsByName( radioName );

  for( var r in ratings ) {
    if( ratings[r].checked )
      return ratings[r].value;
  }

  return null;
}

然后on_sent_ok: if( getRating( "radio-935 ") == 9 ) { location.replace('http://www.google.com') } else { location.replace('http://www.msn.com') }

简单的方法:-)

on_sent_ok: if( $( "input[name='radio-935']:checked" ).val() == 9 ) { location.replace('http://www.google.com') } else { location.replace('http://www.msn.com') }

这是一个很简单的方法

on_sent_ok:“ var sol = $(“ input [name = radio-935]:checked”)。val(); if(sol =='9'){location =' http://google.com ';} else {location =' http://msn.com ';}“

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM