我将此代码放在我的网站上,以动态地将电话号码文本更改为Google转发号码,以跟踪来自我的adwords帐户的电话。它对我的一些其他帐户非常有用,这些帐户的电话号码文本只在代码中显示一次。
我当前网站的问题是电话号码文本在代码中显示2-3个不同的时间和地点。它是<a>
可点击链接代码,实际电话号码文本和图片alt显示文字的一部分。当我运行我当前的代码时,它只会动态地查找可点击链接中数字的第一个isntance。我是否可以添加一个循环来更改此代码的所有实例?
<script type="text/javascript">
(function(a,e,c,f,g,h,b,d){var k={ak:"949530000",cl:"jlDbCPj912oQkNvixAM"};a[c]=a[c]||function(){(a[c].q=a[c].q||[]).push(arguments)};a[g]||(a[g]=k.ak);b=e.createElement(h);b.async=1;b.src="//www.gstatic.com/wcm/loader.js";d=e.getElementsByTagName(h)[0];d.parentNode.insertBefore(b,d);a[f]=function(b,d,e){a[c](2,b,k,d,null,new Date,e)};a[f]()})(window,document,"_googWcmImpl","_googWcmGet","_googWcmAk","script");
//Change the values in this section to customise for your implementation.
//Replace with business's phone number EXACTLY as it appears on the website.
var business_number = "866-755-8858";
//Replace with business's phone number without spaces or symbols.
var business_number_unformatted = "8667558858";
//Replace this value with the unique selector for the phone number's element.
var business_number_identifier = "p#dealerPhoneNum";
//End customization section
var callback = function(formatted_number, unformatted_number) {
var numberElement = document.querySelector(business_number_identifier);
var numberString = numberElement.innerHTML;
numberString = numberString.replace(business_number,formatted_number);
numberElement.innerHTML = numberString;
};
//The line of code below is for testing with GTM's debug mode.
//It replaces the business phone number with a testing number (01234 567891).
window.onload = callback('01234 567891', business_number_unformatted);
//This code executes everything. When you're done testing and you're ready to publish the
//GTM container, place '//' in front of the code above, and remove the '//' below.
//window.onload = _googWcmGet(callback, business_number);
</script>
答案 0 :(得分:1)
更改此行:
var business_number_identifier = "p#dealerPhoneNum";
到
var business_number_identifier = "p.dealerPhoneNum";
和
更改所有html:
<p id="dealerPhoneNum">
到
<p class="dealerPhoneNum">
了解更多https://developer.mozilla.org/en/docs/Web/Guide/CSS/Getting_started/Selectors