过去 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') }
关于javascript - Wordpress 联系表 7 单选按钮值重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27074898/