我试图删除一个页面上的一个JavaScript效果this网站。每次我尝试删除导致效果的id
时,它会杀死整个页面上的所有js。我甚至尝试删除对js文件中id
的引用,但是也杀死了页面上的所有js。删除身份证正在终止所有的JavaScript页
我不想在js文件中编辑函数,因为我想在其他页面上保留js效果。
这是基本的HTML:
<div class="large-image" id="large-image">
<img src="{{ product.images.first | product_img_url: 'large' }}" class="image-zoom" alt="Picture of {{ product.title | escape }}">
</div>
如果我删除了页面上id="large-image"
所有的JS停止工作。
以下是完整的HTML(它使用液体模板引擎):
{% if product.images != nil %}
<div class="half left product-images">
<div class="large-image" id="large-image">
{% if product.compare_at_price_max > product.price %}<span class="sale-banner">Sale</span>{% endif %}
<img src="{{ product.images.first | product_img_url: 'large' }}" class="image-zoom" alt="Picture of {{ product.title | escape }}">
</div>
下面是相关JS:
(function() {
if (document.getElementById('product')) {
var p = document.getElementById('product'),
b = document.getElementById('large-image'),
i = b.getElementsByTagName('img')[0],
l = document.getElementById('product-image-list');
这里是全功能:
(function() {
if (document.getElementById('product')) {
var p = document.getElementById('product'),
b = document.getElementById('large-image'),
i = b.getElementsByTagName('img')[0],
l = document.getElementById('product-image-list');
if (l) {
var a = l.getElementsByTagName('a');
}
i.onload = function(e) {
var p = this.parentNode;
p.className = p.className.replace(' loading', '');
};
if (window.innerWidth && window.innerWidth > 640) {
var s = document.createElement('span');
s.className = 'enlarge-icon';
s.innerHTML = 'View Large Image';
b.appendChild(s);
b.className += ' action';
b.onclick = function(e) {
e = e || window.event; e = e.target || e.srcElement;
e = getParentByTagName(e, 'DIV');
if (e) {
if (p.className.indexOf('enlarged') !== -1) {
e.className += ' loading';
p.className = p.className.replace(' enlarged', '');
i.src = i.src.replace('grande', 'large');
s.innerHTML = 'View Large Image';
} else {
e.className += ' loading';
i.src = i.src.replace('large', 'grande');
p.className += ' enlarged';
s.innerHTML = 'View Smaller Image';
}
}
}
}
if (l) {
l.onclick = function(e) {
e = e || window.event; e = e.target || e.srcElement;
e = getParentByTagName(e, 'A');
if (e && e.className != 'current') {
b.className += ' loading';
var u = e.href;
if (p.className.indexOf('enlarged') === -1) {
u = u.replace('grande', 'large');
}
i.src = u;
for (var j=0; j<a.length; j++) {
if (a[j].className.indexOf('current') != -1) {
a[j].className = a[j].className.replace('current', '');
}
}
e.className = 'current';
}
return false;
};
}
}
})();
感谢您的帮助!
“杀死所有javascript”是什么意思?看看控制台。它给你什么错误? –
我试图删除“查看大图”效果,所以我可以添加不同的效果。我对js很陌生。我只是想弄明白这一点。 – Arel
然后需要删除/替换'b.onclick'功能。 –