所以我使用Magnific Popup,每当我使用自己的内联模板并对标记进行整个解析时,失败的行是231.这是我的代码:
http://codepen.io/anon/pen/WbaWLa
这是我的HTML:
<div id="featured-works" class="gallery">
<div class="piece">
<a rel="gallery" title="Girl Holding Flowers" href="/themes/images/grid/image1.png" data-description="This one has a description">
<p class="caption">Girl Holding Flowers</p>
<img src="/themes/images/grid/image1.png" alt="image" />
</a>
</div>
<div class="piece">
<a rel="gallery" title="Girl Kissing Father" href="/themes/images/grid/image2.png" data-description="">
<p class="caption">Girl Kissing Father</p>
<img src="/themes/images/grid/image2.png" alt="image" />
</a>
</div>
</div>
这是我的Javascript:
var data = [];
$('.gallery a').each(function(e) {
var item = {
title: $(this).attr('title'),
href_img: $(this).attr('href'),
description: $(this).attr('data-description')
};
data.push( item );
});
$(".gallery").magnificPopup({
delegate: 'a',
type: 'image',
items: data,
type: 'inline',
closeOnContentClick: true,
inline: {
// Define markup. CLass names should match key names.
markup: '<div class="white-popup"><div class="mfp-close"></div>' +
'<span class="mfp-title"></span>' +
'<div class="mfp-href"></div>' +
'<div class="mfp-description"></div>' +
'</div>'
},
gallery: {
enabled: true
}
});
失败的行是在_parseMarkup函数中的大量弹出窗口中的231。这就是该函数的外观:
_parseMarkup: function(b, c, d) {
var e;
d.data && (c = a.extend(d.data, c)), y(f, [b, c, d]), a.each(c, function(a, c) {
if (c === undefined || c === !1) return !0;
e = a.split("_");
if (e.length > 1) {
var d = b.find(j + "-" + e[0]);
if (d.length > 0) {
var f = e[1];
f === "replaceWith" ? d[0] !== c[0] && d.replaceWith(c) : f === "img" ? d.is("img") ? d.attr("src", c) : d.replaceWith('<img src="' + c + '" class="' + d.attr("class") + '" />') : d.attr(e[1], c)
}
} else b.find(j + "-" + a).html(c)
})
},
代码:e = a.split("_");
是失败的......它说undefined不是一个函数。我之前做了一个console.log(a),在抛出错误之前,返回0 ..我不知道从哪里得到那个0但不确定。
当我在我的数据变量上执行console.log()时,这就是拉动的内容:
Object, Object]0: Object
description: ""
href_img: "http://rayndee.localhost/themes/light-fixed-width/images/grid/image2.png"
title: "Girl Kissing Father"
__proto__: Object
1: Object
description: "This one has a description"
href_img: "http://rayndee.localhost/themes/light-fixed-width/images/grid/image1.png"
title: "Girl Holding Flowers"
__proto__: Object
length: 2__proto__: Array[0]
感谢您的帮助!