我正在客户汽车销售网站工作,他们与第三家Pty供应商签订合同,该供应商提供了一个可在其库存结果和详细信息页面上运行的脚本。
库存清单结果和详细信息页面是动态数据驱动,从数据库源中提取车辆数据。
我想做什么:
以下是我试图动态插入每个车辆列表的第三个PTY代码块:
<div class="lowPrice">
<a href="javascript:displayLoanInfo(vehicleVIN, SourceID);" id="lbl'+vehicleVIN+'"></a>
<script type="text/javascript">
GetLowestPayment('vehicleVIN', 'SourceID', "lbl'+vehicleVIN+'");
function AssignLowestPayment(LowestPaymentValue, ClientLabelID) {
if (LowestPaymentValue !== '') {
document.getElementById(ClientLabelID).innerHTML = LowestPaymentValue;
};
};
</script>
我已经设置了一个.JS文件已经通过$(getScript)函数加载到客户端脚本中了,我知道足够的JQuery能够从页面中获取每辆车的数据元素并传递给函数(我相信我已经做到了这一点)。但是,我仍然需要插入上面的代码,并将那些包含必要数据元素的变量正确传递给它。
这是我到目前为止写的我的.JS文件中的代码:
var loc = document.location;
var endrive = /inventory-results|inventory-details/.test(loc.pathname);
var SourceID = '10057', ChromeStyleID = '', vehicleZipCode='06473', mode = 'text',vehicleCondition = "",lresult,dresult;
if(/selectedcat\/new/.test(loc.pathname)){ vehicleCondition = "New";}
if(/selectedcat\/preowned/.test(loc.pathname)){ vehicleCondition = "Preowned";}
if(/inventory-results/.test(loc.pathname)){ divblock = '.piiResultsContainer'; lresult = true;cnt=-1}
if(/inventory-details/.test(loc.pathname)){ divblock = '#dt_vehicle_tbl';dresult= true;cnt=-1}
var vdata = [], vattr,vehicleVIN,vehicleStockNum,vehicleTransmission,vehicleOdometer,vehicleExtColor,vehiclePrice,vehicleStyle,vehiclePhoto,vehicleYear,vehicleMake,vehicleModel,vehicle;
if(endrive){
$.getScript("http://www.velocitylogix.com/OfferLogix.js?width=960px&height=700&pack=false",function(){
$(divblock).each(function(){
if(lresult){
vdata['vehiclePrice'] = $(this).find('#ulPricing li:first-child').text().trim();
attrsearch = 'ul#att_listL li';
SourceID = '10057';
}
if(dresult){
vdata['vehiclePrice'] = $(this).find('#dt_vehicle_listing').find('ul#ulPricing li:first-child').text().trim();
attrsearch = '#dt_vehicle_attribute ul#att_listL li';
SourceID = '10057';
}
if(/MSRP/.test(vdata['vehiclePrice'])){ vdata['vehiclePrice'] = vdata['vehiclePrice'].replace("MSRP: ","");}
if(/Selling Price/.test(vdata['vehiclePrice'])){ vdata['vehiclePrice'] = vdata['vehiclePrice'].replace("Selling Price: ","");}
var tlist = $(this).find(attrsearch).each(function(){
vattr =$(this).find('span').text();
switch(vattr){
case "VIN:":vdata['vehicleVin']=$(this).text().replace("VIN: ","");
break;
case "Stock #:":vdata['vehicleStockNum']=$(this).text().replace("Stock #: ","");
break;
case "Miles:":vdata['vehicleOdometer']=$(this).text().replace("Miles: ","");
break;
default :
vdata['vehicleOdometer']= 0;
break;
}
vehiclePrice = vdata['vehiclePrice'];
vehicleVIN = vdata['vehicleVin'];
});
cnt++;
GetLowestPayment(vehicleVIN, SourceID, 'lbl' + vehicleVIN);
function AssignLowestPayment(LowestPaymentValue, ClientLabelID) {
if(LowestPaymentValue !== '') {
document.getElementById(ClientLabelID).innerHTML = LowestPaymentValue;
};
};
$(this).find('#ulPricing').append('<div style="max-width:260px; position:relative;z-index: auto;"><div id="din_'+cnt+'" style="white-space: nowrap;"></div><div class="lowPrice"><a href="javascript:displayLoanInfo(vehicleVIN, SourceID);" id="lbl'+vehicleVIN+'"></a></div></div>');
});
});
}
非常感谢任何帮助。