0
我有產品網格,每個產品都會調用JavaScript以及用於打開iframe窗口的唯一ID。 當調用第一個函數時它工作正常,但是在調用第二個函數時它什麼也不做。 我將有大約20種需要調用該腳本的產品。2個或更多功能無法在Javascript中執行
我想如果可能的時候調用第二個iframe,第一個關閉,第二個出現等。
下面是腳本:
function init() {
test = true;
document.getElementById('go<?php echo $product['product_id']; ?>').onclick = function() {
ifr = document.createElement('iframe');
ifr.setAttribute('src', this.href);
ifr.src = this.href;
ifr.setAttribute('id', 'iframe_a<?php echo $product['product_id']; ?>');
if (test == true) {
ifr.onreadystatechange = function() {
if (this.readyState == 'complete<?php echo $product['product_id']; ?>') {}
}
document.getElementById('iframe_a_container<?php echo $product['product_id']; ?>').appendChild(ifr);
test = false;
}
return false;
}
}
window.addEventListener ?
window.addEventListener('load', init, false) :
window.attachEvent('onload', init);
的iframe代碼:
<div id="iframe_a_container<?php echo $product['product_id']; ?>"> </div>
和按鈕的代碼:
<a id="go<?php echo $product['product_id']; ?>" href="index.php?route=product/quickview&product_id=<?php echo $product['product_id']; ?>">Quick View</a>
用你的方法,該按鈕只是就像沒有功能的HREF。 該腳本停止工作。它位於onclick內部。這裏是工作腳本http://www.petite-style.com/tea(產品下方的快速查看按鈕) –
用onmouseover嘗試過,它可以與你的代碼一起修改,但它不能完成這項工作。 –