0

我可以在页面加载时自动将 span 类中的文本复制到输入字段,但我无法让 FacetWP 响应并更新结果,即使使用FWP.refresh()

https://facetwp.com/documentation/developers/javascript/facetwp-refresh/

刻面名称 -proximity

跨度类 -local-addrress-name

输入类 -facetwp-location

window.addEventListener('load', function () {
var nodes = document.querySelectorAll('.local-address-name');
var last = nodes[nodes.length- 1];
document.querySelector('.facetwp-location').value =last.innerHTML;
  setTimeout(function() {  
FWP.refresh(); // Change a facet value
         console.log( "ready!" );
  }, 2000);

    
});
<span class="local-address-name">Brunswick, GA, USA</span>

<input type="text" class="facetwp-location" value="" placeholder="Enter Zip or Address" id="facetwp-location" autocomplete="off">

4

1 回答 1

0

FacetWP 依靠隐藏的 lat/lng 字段来完成繁重的工作,然后只是同步所有内容。这是一种通过每个产品页面上的 lat/lng 位置接近度来实现相关产品的简单方法。干杯!

window.addEventListener('load', function () {
var nodes = document.querySelectorAll('.local-address-name');
var last = nodes[nodes.length- 1];
document.querySelector('.facetwp-location').value =last.innerHTML;
});

window.addEventListener('load', function () {
var nodes = document.querySelectorAll('.local-lat-val');
var last = nodes[nodes.length- 1];
document.querySelector('.facetwp-lat').value =last.innerHTML;
});

window.addEventListener('load', function () {
var nodes = document.querySelectorAll('.local-lng-val');
var last = nodes[nodes.length- 1];
document.querySelector('.facetwp-lng').value =last.innerHTML;
FWP.refresh('');
});
于 2019-11-22T21:55:25.960 回答