【问题标题】:Code snippet not working after recent update to wordpress最近更新到 wordpress 后代码段不起作用
【发布时间】:2020-06-03 20:41:08
【问题描述】:

大家好,在 wordpress 的最新更新之后,我似乎有点难过,这个功能已经停止工作。任何想法将不胜感激。 . .

首先 sn-p 获取参数“we”,然后在进行一些计算后自动填充表单字段 id #input_2_4。

`<script>
$.urlParam = function (name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)')
                  .exec(window.location.href);
return results[1] || 0;
}
var we = parseInt( $.urlParam('we') );
$('#input_2_4').val( '£' + (we * 0.1450).toFixed(2));
</script>`

url 字符串中似乎存在所有内容,包括 &we=1685 值,但字段 #input_3_4 现在为空白。

Link

【问题讨论】:

  • 控制台日志显示Uncaught TypeError: Cannot set property 'urlParam' of undefined,这就是我要开始的地方。我还会考虑 WordPress jQuery 交互中 $ vs jQuery 的正常问题。
  • 感谢 Tom,将调查 jQuery 冲突。

标签: wordpress forms parameters gravity


【解决方案1】:

我会像下面这样尝试删除任何$ issues。 Console.log 应该让您知道问题是否在于获取 URL 参数。您可能还需要查看enqueueing 脚本,以确保它以正确的顺序加载。

jQuery.urlParam = function (name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)')
                  .exec(window.location.href);
  console.log(window.location.href)
  console.log(results[1] || 0);
return results[1] || 0;
}
var we = parseInt( jQuery.urlParam('we') );
jQuery('#input_2_4').val( '£' + (we * 0.1450).toFixed(2));

【讨论】:

    猜你喜欢
    • 2020-08-02
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    相关资源
    最近更新 更多