2017-07-25 46 views
-1
function(){i.image&&(s.cover.classList.add(o+"-cover"),s.cover.style.width=i.imageWidth+"px", 

s.cover.style.backgroundImage="url("+i.image+")", 
s.cover.style.height=i.imageWidth+"px", 

i.rtl?s.toastBody.style.marginRight=i.imageWidth+10+"px":s.toastBody.style.marginLeft=i.imageWidth+10+"px",s.toast.appendChild(s.cover))}(), 

會取得的成果之上的JavaScript添加超鏈接如下:如何在min.js功能

<div class="iziToast-cover" style="width: 70px; background-image:url」../img/123.jpg」);"></div> 

我想補充一個的onclick功能,它成爲:

<div class="iziToast-cover" **onclick="location.href='newurl.html';"** style="width: 70px; background-image: url」../img/123.jpg」);"></div> 

我已經嘗試s.cover.onclick.location.href ='newurl.html',但無法正常工作。

任何人都可以告訴我我應該添加什麼js代碼?

回答

0

所以添加事件偵聽器

s.cover.addEventListener("click", function() { 
    window.location.href = "http://www.example.com"; 
}); 
+0

我想你混淆了一些... –

+0

哈哈....大腦是ES6 – epascarello

+0

值得指出的如果URL位置可以不同,可以在設置一個data- *屬性並在點擊時檢索,但是如果url沒有改變,這個回答將會完成這項工作。 – Adriani6