嗨,我有点沮丧,似乎在对wordpress的最新更新之后,此功能停止了工作。任何想法将不胜感激。 。 。
第一个代码段获取参数“ 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>`
似乎所有包含&we = 1685值的url字符串中都包含所有内容,但是字段#input_3_4现在为空白。
我会像下面那样尝试删除所有$ 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));