是否有jQuery、javascript或.php脚本允许我根据邮政编码列表显示不同的页面?例如,如果用户在"有效"zip列表中输入邮政编码,则会显示pageA.php,否则会显示pageB.php。这些邮政编码值可以手动列出,也可以包含在.csv文件中,只要最简单。
输入后显示的页面将基于用户输入,如:
<input name="zipcode" id="zipcode" type="text" />
理想情况下,有效的邮政编码将列为:
<script>
var zipcodelist = ['12345','12346','12347','12348'];
更新的解决方案这是我正在使用的代码:
<script type="text/javascript">
$(function(){
var zipCodes = ['92056', '90210', '92121', '92101'];
$('#zip_form').submit(function(){
$('#id_div_one, #id_div_two').hide();
var theZip = $('#id_zip_code').val();
if(jQuery.inArray(theZip,zipCodes) > -1) {
$('#id_div_one').fadeIn();
} else {
$('#id_div_two').fadeIn();
}
return false;
});
});
</script>
您可能只需要获取邮政编码的发布值,然后在应用程序逻辑中重定向到您想要的页面。例如在PHP中:
$special_zip_codes = array(
'10000',
'10002',
'10003' // and so forth
);
$zip = $_POST['zip_code'];
// need to add whatever validation/sanitation of zip code value here
if(in_array($zip, $special_zip_codes)) {
header('Location: http://www.domain.com/fileA.php');
} else {
header('Location: http://www.domain.com/fileB.php');
}
exit();
制作一个php文件,该文件将从html文件(具有pincode)中获取数据,比如使用post或get然后从excel表或DB中检查pincode并执行所需操作。