我一直在滾動的年齡現在的解決方案,我似乎無法使它的工作。PHP的IMG懸停和顯示到不同的IMG標記
我想製作某種圖書館,你可以懸停在圖標上,而將鼠標懸停在圖像標籤上。正如你從下面的圖片中看到的,我的php語句在左邊返回了2個圖像。當我盤旋時,我想讓懸停的圖像顯示在大img標籤中。但懸停不起作用。
這裏是我的javascript
<script type="text/javascript">
//imageview
$(document).ready(function loading(){
var getimg = document.getElementById("icoimg").getAttribute("src");
document.getElementById("selectedimg").src = getimg;
});
</script>
這裏是我的php的mysqli while循環
$count = 1;
if($count <= 6){
while($row = mysqli_fetch_array($query)) {
$imgcase = $row['Showcase_Image'];
$itemname = $row['Product_Name'];
$itemid = $row['Product_ID'];
echo "<div class='imgico' id='imgico'><img id='icoimg' name='icoimg' src=$imgcase onmouseover='loading();' /></div></br>";
$count++;
}
}
,這是大IMG預覽
<div class="imgprev" id="imgprev" width="460" height="300"><img id="selectedimg" width="460" height="300" /></div>
我嘗試了很多技巧,我嘗試發明自己的代碼。我在網上搜索,但沒有運氣。我在想的是MAYBE,因爲生成的ID在標籤內有相同的ID,也許我的IMG懸停是無用的。也許我需要找到一種方法來獲得每個生成的id標籤一個唯一的id和調用,然後調用該標籤的id應該是「唯一」在JavaScript中,然後應用函數?如果是的話如何? 任何可以幫助我的救生員? Thx提前! PHP和Javascript只..沒有CSS PLZ(除非它唯一的希望...大聲笑)
編輯:我做了一個「硬編碼」,它的工作,但即使是它的硬編碼我不希望它像這樣工作。我想顯示最多5個圖像,這就是爲什麼我的php代碼中我的while循環之前有一個計數函數。但如果我不能找到一個更好的辦法,我想我只是要堅持這個外行hardscript笑
if($count <= 6){
while($row = mysqli_fetch_array($query)) {
$imgcase = $row['Showcase_Image'];
$itemname = $row['Product_Name'];
$itemid = $row['Product_ID'];
echo "<div class='imgico' id='imgico'><img id=$count name='icoimg' src=$imgcase onmouseover='loading$count();' /></div></br>";
$count++;
function loading1(){
var getimg = document.getElementById("1").getAttribute("src");
document.getElementById("selectedimg").src = getimg;
};
function loading2(){
var getimg = document.getElementById("2").getAttribute("src");
document.getElementById("selectedimg").src = getimg;
};
function loading3(){
var getimg = document.getElementById("3").getAttribute("src");
document.getElementById("selectedimg").src = getimg;
};
function loading4(){
var getimg = document.getElementById("4").getAttribute("src");
document.getElementById("selectedimg").src = getimg;
};
function loading5(){
var getimg = document.getElementById("5").getAttribute("src");
document.getElementById("selectedimg").src = getimg;
};
echo "<div class='imgico'><img name='icoimg' src=$imgcase onmouseover='loading(this);' /></div></br>";
這是我第一次嘗試。它不顯示圖像。空白。我有一個標籤來顯示元素正在變得什麼 var getimg = elm.getAttribute(「src」); document.getElementById(「lbltest」)。innerHTML = getimg; 沒什麼。 idont得到它大聲笑....硬編碼是唯一使它的工作,但我覺得它太不合格 –
編輯。所以我想知道....我決定刪除$(document).ready並且使這個函數成爲這個函數的一個函數。 document.getElementById(「selectedimg」)。src = getimg;' 現在它的工作方式就像它的工作......這就是奇怪的大聲笑。現在唯一的事情是那些我打開頁面,它不會自動選擇頁面加載的第一個圖像。我必須懸停它才能顯示。 –