我有这个带有特定功能的代码来显示输出,我必须将来自 JSON 的 {{url}} 值获取到按钮的 onclick() 事件。在此代码下方进行了说明。请参阅以下代码中的片段,搜索“更多”。它是一个带有 onclick() 的按钮。
fixlinedetail: function () {
window.tBuilder.tpl[tType.linedetail] = function (a) {
var b = $("#dvLineReview_Buttons .button.shiny-blue").css({'vertical-align': 'top', width: (setting.basic.screenW - 105) + 'px', 'height':'33px', 'text-shadow':'none', 'top':'0', 'margin-top':'3px','margin-right': '50px'}),
c = "",
d = {
id: a.id,
info: _.unescapeHTML(globalData.decode(a.info)),
phone: a.phone,
email: a.email,
url: a.url,
IMGS: a.images,
logo: "'" + a.logo + "'"
};
b[!0 === a.follow || "true" === a.follow || 1 === a.follow || "1" === a.follow ? "show" : "hide"]();
jqobject.layout.slideIn.lineDetail.Map.change(a.coord.lat, a.coord.lng, {
isPreview: !0
});
c = $(_.mTemplate('<article style="min-height: 170px;"><div class="stack twisted" data-imgIndex="0"><div style="background-image: url({{{logo}}});"></div></div> {{{info}}}</article> <a id="btnAddToCal_Review" class="button skip off" href="#">Add to Calendar</a> <a class="button skip" href="tel:{{phone}}">Call Us</a> <a class="button skip" href="mailto:{{email}}">Email Us</a> <button class="button skip" onclick="inappbrowser()" type="submit"> More </button>',
d));
!d.logo && 0 === d.IMGS.length ? c.find(".stack").hide() : 0 !== d.IMGS.length && (d.logo || c.filter(".stack div").css("background-image", 'url("' + d.imgs[0] + '")'), c.filter(".stack").fastClick(function () {
var a = $(this);
global.ImageSlider.triggerSlides(a, d.id, d.imgs, a.data("imgIndex"))
}));
if (!1 === !a.date && (!0 !== !a.date.start || !0 !== !a.date.start) && !a.date.complete) try {
!1 === global.data.method.customer.event.options.check(a.id).added && c.filter("#btnAddToCal_Review").removeClass("off").css({
display: "block"
}).attr("onclick",
_.mTemplate("if(confirm(" + _.quote("Are you sure you wish to add this event?") + ")) { $(this).hide(); window.Pl.calendar.createEvent({{{ id }}}, {{{ title }}},{{{ location }}},{{{ notes }}},{{{ startDate }}},{{{ endDate }}}); }; return false;", {
id: _.quote(a.id),
title: _.quote(globalData.decode(a.name)),
location: _.quote(globalData.decode(a.address)),
notes: '" "',
startDate: _.quote(a.date.start),
endDate: _.quote(a.date.end)
}))
} catch (f) {}
return c
}
},
主要问题是这个函数(如下所述)超出了范围。
function inappbrowser() {
iabRef = window.open('url', '_blank', 'location=yes');
iabRef.addEventListener('loadstart', iabLoadStart);
iabRef.addEventListener('loadstop', iabLoadStop);
iabRef.removeEventListener('loaderror', iabLoadError);
iabRef.addEventListener('exit', iabClose);
}
告诉我一种在函数的 'url' 字段中获取 {{url}} 值的方法。