我刚刚开始使用JavaScript。请原谅我在这里发布整个代码。由于有人建议发布完整的代码,我正在这样做,因为我渴望做到这一点。
我正在尝试将用户重定向到#34;感谢您的页面",具体取决于他们的区域,在提交页面时。就像你看到的,有很多形式,我试图通过他们的areacode找出他们的省。因为我对javascript很新。我想请你帮忙。
我基本上要做的是向用户展示不同的"感谢您的页面"。 想象一个页面说谢谢,您在不列颠哥伦比亚省的当地代表将与您联系。
所以这是我的尝试,目前无法正常工作,我无法找到原因。
<!--=== Content Part ===-->
<div class="container content">
<div class="title-box">
<div class="title-box-text"><span class="color-green">Book a Demo</span></div>
<p>With ClearDent, you can do everything. Better.</p>
</div>
<!-- Content Blocks -->
<div class="row">
<!-- Homework for Jason Begin -->
<div class="col-md-6 col-md-offset-3">
<!-- Homework for Jason End -->
<form id="sfDemoForm" action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" class="sky-form">
<input name="captcha_settings" value="{"keyname":"IC_ClearDent_Main_Demo","fallback":"true","orgId":"00D1I0000002QyG","ts":""}" type="hidden">
<input name="oid" value="00D1I0000002QyG" type="hidden">
<input name="retURL" value="https://test.cleardent.com/demo-thankyou.html" type="hidden">
<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: These fields are optional debugging elements. Please uncomment -->
<!-- these lines if you wish to test in debug mode. -->
<!-- <input type="hidden" name="debug" value=1> -->
<!-- <input type="hidden" name="debugEmail" value="ppli@cleardent.com"> -->
<!-- ---------------------------------------------------------------------- -->
<fieldset>
<!--<label class="label" for="first_name">First Name</label>-->
<label class="input margin-bottom-15"><i class="icon-prepend fa fa-user"></i>
<input id="sffirst_name" maxlength="40" name="first_name" size="20" type="text" required placeholder="First name">
</label>
<!--<label class="label" for="last_name">Last Name</label>-->
<label class="input margin-bottom-15"><i class="icon-prepend fa fa-user"></i>
<input id="sflast_name" maxlength="80" name="last_name" size="20" type="text" required placeholder="Last name">
</label>
<!--<label class="label" for="email">Email</label>-->
<label class="input margin-bottom-15"><i class="icon-prepend fa fa-envelope"></i>
<input id="sfemail" maxlength="80" name="email" size="20" type="email" required placeholder="Email address">
</label>
<!-- <label class="label" for="phone">Phone</label>-->
<label class="input margin-bottom-25"><i class="icon-prepend fa fa-phone"></i>
<input id="sfphone" maxlength="40" name="phone" size="20" type="text" required placeholder="Phone">
</label>
<!--<label class="label" for="description">Notes</label>-->
<label class="textarea textarea-resizable margin-bottom-25">
<textarea id="sfdescription" name="description" placeholder="Is there something specific you want to see from ClearDent?"></textarea>
</label>
<input id="sfstate" name="state" type="hidden">
<input id="sflead_source" name="lead_source" type="hidden" value="Website">
<input id="sfcompany" name="company" type="hidden">
<input id="sfCampaign_ID" name="Campaign_ID" type="hidden" value="7011I000000d5auQAA">
</fieldset>
<div id="recaptcha" class="g-recaptcha" data-sitekey="6LeXmEAUAAAAAG7VJd6Z8YCVkP44AgAlqCUmpRAi" data-callback="submitDemoToLead" data-size="invisible"> </div>
<footer>
<button id="sfdemoPreSubmit" class="btn-u"><i class="fa fa-paper-plane fa-fw"></i> Get Your Free Demo</button>
<!--<button class="btn-u btn-brd" onclick="window.history.back();"><i class="fa fa-arrow-left fa-fw"></i> Back</button>-->
</footer>
</form>
</div>
</div>
<!-- End Content Blocks -->
</div>
<!--=== End Content ===-->
<!-- InstanceEndEditable -->
<!--=== Footer Version 1 ===-->
<div class="footer-v1">
<div class="footer">
<div class="container">
<div class="row">
<!-- Social -->
<div class="col-md-3 md-margin-bottom-40">
<div class="row">
<div class="col-xs-12"><a href="../">
<div class="logo"> </div>
</a></div>
</div>
<div class="row">
<div class="col-xs-12">
<p>Subscribe to ClearDent Newsletter</p>
</div>
</div>
<div id="mc_embed_signup" class="row margin-bottom-20">
<form action="//cleardent.us2.list-manage.com/subscribe/post?u=c94a01df02408fee7e80ba656&id=3d0b9b204d&MERGE3=Web" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="form-inline" target="_blank">
<div class="col-xs-12">
<div class="input-group">
<label class="sr-only" for="mce-EMAIL">Email address</label>
<span class="input-group-addon colour-cleardent"><i class="fa fa-newspaper-o fa-fw"></i></span>
<input type="email" name="EMAIL" class="form-control" id="mce-EMAIL" placeholder="Email address" required>
<span class="input-group-btn">
<button type="submit" id="mc-embedded-subscribe" class="btn-u form-control">Subscribe</button>
</span> </div>
</div>
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;" aria-hidden="true">
<input type="text" name="b_c94a01df02408fee7e80ba656_3d0b9b204d" tabindex="-1" value="">
</div>
</form>
</div>
<div class="row">
<div class="col-xs-12">
<div class="headline">
<h2>Connect With Us</h2>
</div>
<div class="social-connect">
<button class="btn btn-lg btn-rss" onclick="window.open('http://marketing.cleardent.com/')"><i class="fa fa-2x fa-rss"></i></button>
<button class="btn btn-lg btn-facebook" onclick="window.open('https://www.facebook.com/ClearDentSoftware')"><i class="fa fa-2x fa-facebook"></i></button>
<button class="btn btn-lg btn-twitter" onclick="window.open('https://twitter.com/ClearDentCanada')"><i class="fa fa-2x fa-twitter"></i></button>
<button class="btn btn-lg btn-googleplus" onclick="window.open('https://plus.google.com/+CleardentCanada/?prsrc=3')"><i class="fa fa-2x fa-google-plus"></i></button>
</div>
</div>
</div>
</div>
<!--/col-md-3-->
<!-- End Social -->
<!-- Badge -->
<div class="col-md-3 md-margin-bottom-40">
<div class="posts">
<div class="headline">
<h2>Seal of Approval</h2>
</div>
<ul class="list-unstyled latest-list">
<li> <a href="iso-certification-and-academy-of-general-dentistry-approval.html" id="footer-2-iso">
<div class="iso-logo"></div>
</a><small class="iso-logo-text">FM584056</small></li>
<li> <a href="iso-certification-and-academy-of-general-dentistry-approval.html" id="footer-2-agd">
<div class="agd-logo"></div>
</a><small class="agd-logo-text">1/4/2017 - 31/3/2019 | AGD Provider ID: 32124</small></li>
</ul>
</div>
</div>
<!--/col-md-3-->
<!-- End Badge -->
<!-- Link List -->
<div class="col-md-3 md-margin-bottom-40">
<div class="headline">
<h2>Popular Pages</h2>
</div>
<ul class="list-unstyled link-list">
<li><a href="../" id="footer-2-home">Features</a><i class="fa fa-angle-right"></i></li>
<li><a href="marketing/" id="footer-2-blog">Blog</a><i class="fa fa-angle-right"></i></li>
<li><a href="support/" id="footer-2-support">Support</a><i class="fa fa-angle-right"></i></li>
<li><a href="free-tools/training-videos.php" id="footer-2-videos">Training Videos</a><i class="fa fa-angle-right"></i></li>
<li><a href="events/" id="footer-2-events">Events</a><i class="fa fa-angle-right"></i></li>
</ul>
</div>
<!--/col-md-3-->
<!-- End Link List -->
<!-- Address -->
<div class="col-md-3 md-margin-bottom-40">
<div class="contact-info-area">
<div class="contact-info">
<div class="headline">
<h2>Contact Us</h2>
</div>
<address>
166-5489 Byrne Road<br>
Burnaby BC<br>
Canada V5J 3J1
<table>
<tr>
<td class="addr-icon"><i class="fa fa-phone"></i></td>
<td class="addr-list-text"><a href="tel:+18662532748" id="footer-2-phone">1-866-253-2748</a></td>
</tr>
<tr>
<td class="addr-icon"><i class="fa fa-fax"></i></td>
<td class="addr-list-text"><a href="fax:+18666110548" id="footer-2-fax">1-866-611-0548</a> (Fax)</td>
</tr>
<tr>
<td class="addr-icon"><i class="fa fa-envelope"></i></td>
<td class="addr-list-text"><a href="mailto:info@cleardent.com" id="footer-2-email">info@cleardent.com</a></td>
</tr>
</table>
</address>
</div>
<div class="map-img"></div>
</div>
</div>
<!--/col-md-3-->
<!-- End Address -->
</div>
</div>
</div>
<!--/footer-->
<div class="copyright">
<div class="container">
<div class="row">
<div class="col-md-6">
<p>© ClearDent | <a href="privacy.html" id="footer-2-privacy">Privacy Policy</a></p>
</div>
<!-- Social Share Links -->
<div class="col-md-6">
<div class="social-icons pull-right">
<p>Share this page:
<button class="btn btn-sm rounded-4x btn-facebook" onClick="window.open('https://www.facebook.com/dialog/share?app_id=211125742252409&display=popup&href=' + encodeURI(window.location.href) + '&redirect_uri=https%3A%2F%2Fwww.cleardent.com%2F')"><i class="fa fa-facebook"></i></button>
<button class="btn btn-sm rounded-4x btn-twitter" onClick="window.open('https://twitter.com/intent/tweet?via=cleardentcanada&url=' + encodeURI(window.location.href))"><i class="fa fa-twitter"></i></button>
<button class="btn btn-sm rounded-4x btn-googleplus" onClick="window.open('https://plus.google.com/share?url=' + encodeURI(window.location.href))"><i class="fa fa-google-plus"></i></button>
</p>
</div>
</div>
</div>
<!-- End Social Share Links -->
</div>
</div>
</div>
<!--/copyright-->
<!--=== End Footer Version 1 ===-->
</div>
<!--/wrapper-->
<!-- Demo Request Success Message -->
<div id="demoSuccessMsg" class="modal fade" tabindex="-1" role="alertdialog" aria-labelledby="demoSuccessLabel" aria-hidden="true">
<div class="modal-dialog modal-sm" role="alert">
<div class="modal-content">
<div class="modal-header">
<button aria-label="Close" data-dismiss="modal" class="close"><i class="fa fa-times fa-fw"></i></button>
<h4 id="demoSuccessLabel" class="modal-title">Demo Request Sent!</h4>
</div>
<div class="modal-body">
<p>Thank you. A ClearDent consultant will contact you via the contact information you have just provided within two (2) business days.</p>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn-u"><i class="fa fa-times fa-fw"></i> Got it!</button>
</div>
</div>
</div>
</div>
<!-- Google Optimize Popup Modal -->
<div id="modalConvert" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="labelConvert">
<div class="modal-dialog" role="document">
<div class="modal-content"> <!-- InstanceBeginEditable name="convertPopup-GoogleOptimize-plugin" -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"><i class="fa fa-times"></i></span></button>
<h4 id="labelConvert" class="modal-title">Like what you see? See even more!</h4>
</div>
<div class="modal-body"> <img class="img-responsive img-spacer margin-bottom-30" src="assets/img/features/cleardent/kiosk.png" alt="iPad Kiosk helps with gathering patient in-take">
<p>Book a demo and one of our friendly consultants can walk you through all the benefits your practice can expect when you choose to implement Kiosk at your practice. Plus, we have many other amazing features that we would be happy to show you as well!</p>
<!-- Demo Menu-->
<form action="#" method="post" id="demo-formPopup" name="demo-formPopup" class="sky-form" onSubmit="return false;">
<fieldset>
<label class="input"><i class="icon-prepend fa fa-user"></i>
<input type="text" name="demo-name" id="demo-namePopup" required placeholder="Your name">
</label>
<label class="input"><i class="icon-prepend fa fa-envelope"></i>
<input type="email" name="demo-email" id="demo-emailPopup" required placeholder="Your email">
</label>
<label class="input"><i class="icon-prepend fa fa-phone"></i>
<input type="tel" name="demo-phone" id="demo-phonePopup" required placeholder="Your phone number">
</label>
<label class="input"><i class="icon-prepend fa fa-commenting"></i>
<input type="text" name="demo-notes" placeholder="Additional notes to us">
</label>
<input class="hidden" type="text" id="n7Q2326JYZ334s58FWq3TrPopup" name="n7Q2326JYZ334s58FWq3Tr" value="bg62U79DPNCTbBvpZHueZG" tabindex="-1" aria-hidden="true">
<input class="hidden" type="text" id="campaignPopup" name="campaign" value="" tabindex="-1" aria-hidden="true">
</fieldset>
<footer>
<div class="form-buttons">
<button id="btnReqDemoPopup" class="btn-u pull-left"><i class="fa fa-paper-plane fa-fw"></i> Book</button>
<button type="button" class="btn-u btn-brd pull-right" data-dismiss="modal"><i class="fa fa-times fa-fw"></i> Close</button>
</div>
<div class="form-sub-msg">
<p>Sending a demo request, please wait…</p>
</div>
</footer>
</form>
</div>
<!-- InstanceEndEditable --> </div>
</div>
</div>
<!-- Google Optimize Popup Modal End -->
<!-- JS Global Compulsory
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/1.4.1/jquery-migrate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
-->
<!-- JS Implementing Plugins
<script src="../assets/1.9.5/plugins/back-to-top.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/smoothscroll/1.4.6/SmoothScroll.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js"></script>
-->
<script src="assets/1.9.7/assets/js/all-page-pack/js/all-page-pack.min.js"></script>
<!-- InstanceBeginEditable name="page-linked-script" --> <!-- InstanceEndEditable -->
<!-- JS Main
<script src="../assets/1.9.5/js/plugins/fancy-box.js"></script>
<script src="../assets/1.9.5/js/app.js"></script>
-->
<!-- JS Customization
<script src="../assets/1.9.5/js/custom2.js"></script>
-->
<script src="assets/1.9.7/assets/js/all-page-pack/js/custom-pack.min.js"></script>
<!-- JS Page Level -->
<script>
function parse_query_string(query) {
var vars = query.split("&");
var query_string = {};
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = decodeURIComponent(pair[1]);
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [query_string[pair[0]], decodeURIComponent(pair[1])];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
}
$(document).ready(function () {
App.init();
FancyBox.initFancybox();
wow = new WOW().init();
$("#demo-phone").mask('(999) 999-9999', {placeholder:'X'});
$("#demo-form").validate({
submitHandler: function(form) {
var query_str = parse_query_string(window.location.search.substring(1));
if (typeof(query_str) || typeof(query_str["utm_campaign"])) {
$("#campaign").val(query_str["utm_campaign"]);
} else {
$("#campaign").val("Not Specified");
}
ga("send", "pageview", "/script/demo.php");
$(".form-buttons").fadeOut("fast");
$(".form-sub-msg").fadeIn("fast");
$.fancybox.showLoading();
$.post("/script/demo.php", $("#demo-form").serialize(), function(data) {
if (data.indexOf("Failed") == -1) {
try {
ga("send", "pageview", "/script/demoed.php");
/* fbq("track", "Purchase", {
value: 1.00,
currency: "CAD",
content_type: "product",
content_ids: ["1"]
});
twq("track", "Purchase", {
value: "1.00",
currency: "CAD",
content_type: "product",
content_ids: ["1"],
num_items: 1
}); */
} catch (e) {}
$.fancybox.hideLoading();
$(".form-sub-msg").fadeOut("fast");
$(".form-buttons").fadeIn("fast");
$("#btnClear").click();
$("#demoSuccessMsg").modal("show");
} else {
$(".form-sub-msg").html("<strong style='color: red;'>Error sending request, please call <a href='tel:+18662532748,1'>1-866-253-2748</a>. Sorry for the inconvenience.</strong>");
}
});
}
});
//Pop-up conversion plugin for Google Optimize
$("#demo-phonePopup").mask('(999) 999-9999', {placeholder:'X'});
$("#demo-formPopup").validate({
submitHandler: function(form) {
var query_str = parse_query_string(window.location.search.substring(1));
if (typeof(query_str) || typeof(query_str["utm_campaign"])) {
$("#campaignPopup").val(query_str["utm_campaign"]);
} else {
$("#campaignPopup").val("Not Specified");
}
ga("send", "pageview", "/script/demo.php");
$(".form-buttons").fadeOut("fast");
$(".form-sub-msg").fadeIn("fast");
$.fancybox.showLoading();
$.post("/script/demo.php", $("#demo-formPopup").serialize(), function(data) {
if (data.indexOf("Failed") == -1) {
try {
ga("send", "pageview", "/script/demoed.php");
fbq("track", "Purchase", {
value: 1.00,
currency: "CAD",
content_type: "product",
content_ids: ["1"]
});
twq("track", "Purchase", {
value: "1.00",
currency: "CAD",
content_type: "product",
content_ids: ["1"],
num_items: 1
});
} catch (e) {}
$.fancybox.hideLoading();
$(".form-sub-msg").fadeOut("fast");
$(".form-buttons").fadeIn("fast");
$('#modalConvert').modal("hide")
$("#demoSuccessMsg").modal("show");
} else {
$(".form-sub-msg").html("<strong style='color: red;'>Error sending request, please call <a href='tel:+18662532748,1'>1-866-253-2748</a>. Sorry for the inconvenience.</strong>");
}
});
}
});
});
</script>
<!-- InstanceBeginEditable name="page-script" -->
<!--Facebook Advanced Matching Start-->
<!-- Homework for Jason Begin (Wrong Use Here; Use Cookie to send successful submit to thank you page) -->
<!--<script>
/*
fbq('init', '697649880319954', {
em: '{{_email_}}',
ph: '{{_phone_}}',
});
*/
</script> -->
<!-- Homework for Jason End -->
<!--Facebook Advanced Matching End-->
<script src="https://www.google.com/recaptcha/api.js"></script>
<script>
//Required Salesforce functions
function timestamp() {
var response = document.getElementById("g-recaptcha-response");
if (response == null || response.value.trim() == "") {
var elems = JSON.parse(document.getElementsByName("captcha_settings")[0].value);
elems["ts"] = JSON.stringify(new Date().getTime());
document.getElementsByName("captcha_settings")[0].value = JSON.stringify(elems);
}
}
window.setInterval(timestamp, 500);
//Masking
$("#sfphone").mask('(999) 999-9999', {placeholder:'X'});
//Form helper functions
function getProvince(pStrPhone) {
var areacode = pStrPhone.substring(0, 3);
switch (areacode) {
case "403":
case "780":
case "587":
case "825":
return "AB";
case "604":
case "778":
case "250":
case "236":
return "BC";
window.location.replace('page1.html');
break;
case "204":
case "431":
return "MB";
case "506":
return "NB";
case "709":
return "NL";
case "867":
return "YT";
case "902":
case "782":
return "NS";
case "416":
case "647":
case "437":
case "519":
case "226":
case "548":
case "613":
case "343":
case "705":
case "249":
case "807":
case "905":
case "289":
case "365":
return "ON";
case "418":
case "581":
case "450":
case "579":
case "514":
case "438":
case "819":
case "873":
return "QC";
default:
return "";
}
}
function cleanPhNum(pStrPhone) {
return pStrPhone.replace("-", "").replace("(", "").replace(")","").replace(" ", "");
}
//Form validation and reCAPTCHA
//Jason Home Work - jQuery Validate and figure out how it validates
$("#sfdemoPreSubmit").click(function(e) {
e.preventDefault();
$("#sfcompany").val($("#sflast_name").val() + ", " + $("#sffirst_name").val());
$("#sfphone").val(cleanPhNum($("#sfphone").val()));
$("#sfstate").val(getProvince($("#sfphone").val()));
$("#sfDemoForm").validate();
if ($("#sfDemoForm").valid()) {
grecaptcha.execute();
}
});
function submitDemoToLead(token) {
$("#sfDemoForm").submit();
}
function redirect() {
var textValue = areacode;
if(textValue == 'BC')
{
location.href = "www.xxx.com/bc";
}
if(textValue == 'AB')
{
location.href = "www.xxx.com/ab";
}
if(textValue == 'ON')
{
location.href = "www.xxx.com/on";
}
else
{
alert("Invalid Input");
}
}
/*
$("#sfDemoForm").validate({
submitHandler: function(form) {
var query_str = parse_query_string(window.location.search.substring(1));
if (typeof(query_str) || typeof(query_str["utm_campaign"])) {
$("#campaign").val(query_str["utm_campaign"]);
} else {
$("#campaign").val("Not Specified");
}
ga("send", "pageview", "/script/demo.php");
$(".form-buttons").fadeOut("fast");
$(".form-sub-msg").fadeIn("fast");
$.fancybox.showLoading();
$.post("/script/demo.php", $("#demo-form").serialize(), function(data) {
if (data.indexOf("Failed") == -1) {
try {
ga("send", "pageview", "/script/demoed.php");
fbq("track", "Purchase", {
value: 1.00,
currency: "CAD",
content_type: "product",
content_ids: ["1"]
});
twq("track", "Purchase", {
value: "1.00",
currency: "CAD",
content_type: "product",
content_ids: ["1"],
num_items: 1
});
} catch (e) {}
$.fancybox.hideLoading();
$(".form-sub-msg").fadeOut("fast");
$(".form-buttons").fadeIn("fast");
$("#btnClear").click();
$("#demoSuccessMsg").modal("show");
} else {
$(".form-sub-msg").html("<strong style='color: red;'>Error sending request, please call <a href='tel:+18662532748,1'>1-866-253-2748</a>. Sorry for the inconvenience.</strong>");
}
});
}
});
*/
答案 0 :(得分:0)
JavaScript可以仅对普通的BC
,AB
和ON
执行类型强制吗?即使您使用的是==
而不是===
,仍然需要将BC
,AB
和ON
括在引号中指示一个文字字符串而不是另一个变量...特别是因为你要比较的textValue
变量(只是areacode
)是一个字符串。