我有以下跟踪像素:
<img id="pixel" alt="" width="1" height="1" src="https://domain.com/file.cfm?amount={tag_amount}&tracking={tag_invoicenumber}&transtype=sale&merchantID=29562" />
Run Code Online (Sandbox Code Playgroud)
我需要在图像源的末尾添加一个变量.这是我正在玩的jQuery.
$('img#pixel [src]').append(affiliateCode);
Run Code Online (Sandbox Code Playgroud)
它不起作用.有什么建议??提前致谢!
Append仅适用于完整DOM对象,您希望附加到src属性.
尝试:
var affiliateCode = '12345';
$('#pixel').attr('src', $('#pixel').attr('src') + '&affiliate=' + affiliateCode);
Run Code Online (Sandbox Code Playgroud)
显然,将参数名称更改为您需要的任何名称.