【发布时间】:2019-02-06 20:51:27
【问题描述】:
我有一个带有三个复选框的表单。用户可以选择这些组合,然后我希望他们在点击表单上的提交按钮后根据他们的选择被重定向到特定页面。
这是在 WordPress 中使用简单的页面 HTML 编辑器完成的。
我在这个网站上对其他类似问题进行了大量研究,但这些答案都对我不起作用。请查看我自己创建的 HTML,以及我在此站点上的研究确定的最终版本的 javascript。
我做错了什么?我是 Javascript 新手。
HTML:
<form id="selections" method="post">
<table class="ss" border="0" cellpadding="0" cellspacing="0">
<tr style="background-color:#ffffff;">
<td class="ss2" width="150"></td>
<td class="ss2" width="100"><center><strong><p style="font-family: arial, sans-serif; color:#009639;" >PDF</p></strong></center></td>
<td class="ss2" width="100"><center><p style="font-family: arial, sans-serif; color:#009639;" ><strong>POSTCARD</strong></p></center></td>
<td class="ss2" width="100"><center><p style="font-family: arial, sans-serif; color:#009639;" ><strong>HTML</strong></p></center></td>
<td class="ss2" width="100"></td>
<td class="ss2" width="150"></td>
</tr>
<tr style="background-color:#DDDDDD; height: 1px;">
<td class="ss"><strong><p style="font-family: arial, sans-serif">Social Security</p></strong></td>
<td class="ss2"><center><input type="checkbox" id="ssPDF" value="1"></center></td>
<td class="ss2"><center><input type="checkbox" id="ssPOSTCARD" value="2"></center></td>
<td class="ss2"><center><input type="checkbox" id="ssHTML" value="3"></center></td>
<td class="ss2"><input class="ss" type="submit" value="SUBMIT" id=SUBMIT></td>
<td class="ss2"><a class="ss" href="http://google.com"><p style="font-family: arial, sans-serif;">PAST ENTRIES</p></a></td>
</tr>
</form>
</table>
Javascript 代码:
<script type="text/javascript">
var ssPDF = $('input[name="ssPDF"]');
var ssPOSTCARD = $('input[name="ssPOSTCARD"]');
var ssHTML = $('input[name="ssHTML"]');
if ( ssPDF.is(':checked') ){
window.location.href="http://www.stackoverflow.com";
}
if ( ssPDF.is(':checked') && ssPOSTCARD.is(':checked') ){
window.location.href="http://www.bing.com";
}
if ( ssPDF.is(':checked') && ssHTML.is(':checked') ){
window.location.href="http://www.google.com";
}
if (ssPDF.is(':checked') && ssHTML.is(':checked') && ssPOSTCARD.is(':checked') ){
window.location.href="http://www.yahoo.com";
}
</script>
【问题讨论】:
标签: javascript html wordpress forms