在提交时使用JavaScript重定向表单插件
我需要帮助,试图重定向wordpress表单插件时,用户点击提交。我可以将javascript添加到表单中,在表单中检查单选按钮的值并基于该值重定向。下面是我试图添加的代码。下面是我在firebug中看到的错误 Javascript:在提交时使用JavaScript重定向表单插件,javascript,forms,redirect,wordpress,Javascript,Forms,Redirect,Wordpress,我需要帮助,试图重定向wordpress表单插件时,用户点击提交。我可以将javascript添加到表单中,在表单中检查单选按钮的值并基于该值重定向。下面是我试图添加的代码。下面是我在firebug中看到的错误 Javascript: on_sent_ok: "if (document.getElementByName('review_stars').value=='4')||(document.getElementByName('review_stars').value=='5') {loca
on_sent_ok: "if (document.getElementByName('review_stars').value=='4')||(document.getElementByName('review_stars').value=='5')
{location = 'http://74.208.11.118:8085/review-submission/'} else { location = 'http://74.208.11.118:8085/review-thank-you/'};"
错误:
SyntaxError: unterminated string literal
"if (document.getElementByName('review_stars').value=='4')||
除非我瞎了眼,否则你会错过你的if声明。试一试:
on_sent_ok: "if (document.getElementByName('review_stars').value=='4' || document.getElementByName('review_stars').value=='5'){location = 'http://74.208.11.118:8085/review-submission/'} else { location = 'http://74.208.11.118:8085/review-thank-you/'};"
下面是一个jQuery解决方案
jQuery(document).ready(function($){
var myform = $("#my_form_id");
myform.submit(function(e){
e.preventDefault();
s = $("[name='review_stars']:checked");
if(s.val() == 1) {
window.location = "http://somedomain.com";
} else if(s.val() == 2) {
window.location = "http://anotherdomain.com";
}
})
});
谢谢你,明白了。不知道我为什么用那种方式使用“()”。