javascript - JS修改基于URL填充联系表单下拉列表
问题描述
在构建网站时,我尝试使用 CF7 的动态文本插件来填充基于先前站点的字段。
但是,虽然它显示了所需的 URL(在加载联系页面后从提议传递到联系页面“www.webpage.com/contact?offer1”,但下拉菜单不会显示想要的选项。
基本上
在报价页面上时 > 按“立即联系”按钮 > 加载带有预归档报价字段的 CF7。
使用 Calluna 主题和 WP 4.9.9
我曾尝试在 wordpress 中使用动态选择扩展名,并且我使用了简码进行选择,但它不起作用。用“if if else”语句替换它是完美的。像这样的东西可以吗?
$(document).ready(function () {
if(window.location.href.contains("?offer1") -1) {
select("offer1");
}
if else(window.location.href.contains("?offer2") -1) {
select("offer2");
}
if else(window.location.href.contains("?offer3") -1) {
select("offer2");
}
if else(window.location.href.contains("?offer4") -1) {
select("offer2");
}
else{
select("Angebote");
}
});
解决方案
这不是很好的方式。使用以下一个;
$(document).ready(function () {
var matchedData = window.location.href.match(/\?(offer(\d))/);
if (matchedData) {
select(matchedData[1]);
return;
}
// default behaviour
select("Angebote");
});
.. 需要映射操作的情况:
$(document).ready(function () {
var matchedData = window.location.href.match(/\?(offer(\d))/);
var actionsMap = new Map([["offer3", "offer2"], ["offer4", "offer2"]])
if (matchedData) {
var actionName = actionsMap.get(matchedData[1]) || matchedData[1];
select(actionName);
return;
}
// default behaviour
select("Angebote");
});
推荐阅读
- c# - 如何取消现有任务并在完成后运行新任务?
- mysql - 如何将 Flask 应用程序容器与 MySQL 服务器容器连接?
- neo4j - Cypher Match-MERGE 查询在 ConstraintValidationFailed 上失败
- reactjs - React、react-sortable-hoc 和多个列表
- c# - 表单应用程序注册表项
- xamarin - 如何将 Xamarin 表单标签 TextType 设置为 HTML?
- php - Laravel 7:如何使用按段设置活动类
- date - Pyspark 格式日期
- html - 浏览器 px 和 css px
- sql - 在 PostgreSQL 的列中连接字符串