简体   繁体   English

当鼠标悬停在图像上时,鼠标悬停失败

[英]When the mouse is over an image onmouseover fails

I'm working on a PHP page that presents data from a database in a table. 我正在处理一个PHP页面,该页面显示表中来自数据库的数据。 Each column in the database is a cell in the table and each column is an 'ATC Station'. 数据库中的每一列都是表中的单元格,每一列都是“ ATC站”。 If it is active, build ul li and when the mouse is over the cell show more data in the central li. 如果处于活动状态,请构建ul li,当鼠标悬停在单元格上方时,在中央li中显示更多数据。

So far so good, everything works perfectlly. 到目前为止,一切都很好。 The problem I faced is when I added an image to the central li and then placed my mouse over the image... It would go from default position to mouse over position like crazy. 我面临的问题是,当我将图像添加到中央li然后将鼠标放在图像上时...它会从默认位置变为鼠标放在疯狂的位置。

var imgURL = "'https://www.ivao.aero/data/images/ratings/atc/";
var data = ["x"];
var lastData = ["x"];

// This is created using a PHP for loop of all data.
data[0] = "Amr Magdy (430603) <br/><img src=" + imgURL + "5.gif'>";
data[1] = " (0) <br/><img src=" + imgURL + ".gif'>";
data[2] = " (0) <br/><img src=" + imgURL + ".gif'>";
data[3] = " (0) <br/><img src=" + imgURL + ".gif'>";
data[4] = " (0) <br/><img src=" + imgURL + ".gif'>";
data[5] = " (0) <br/><img src=" + imgURL + ".gif'>";
data[6] = " (0) <br/><img src=" + imgURL + ".gif'>";
data[7] = " (0) <br/><img src=" + imgURL + ".gif'>";
data[8] = " (0) <br/><img src=" + imgURL + ".gif'>";

function displayData(id) {
    lastData[id] = document.getElementById(id).innerHTML;
    document.getElementById(id).innerHTML = document.getElementById(id).innerHTML + data[id];
}

function hideData(id) {
    document.getElementById(id).innerHTML = lastData[id];
}

http://jsfiddle.net/59jfntxs/ http://jsfiddle.net/59jfntxs/

Here's the for loop I used to create the data array. 这是我用来创建数据数组的for循环。

for($i = 0; $i < count($RFE_stands); $i++)
{
    $data = explode(":", $RFE_stands[$i]['image']);
    echo "data[{$i}] = ";echo '"'.$data[2].' ('.$data[0].') <br/><img src="+imgURL+"'.$data[3].".gif'".'>"'; echo";";
}

EDIT: Here's the solution, with Stefan's help. 编辑:这是解决方案,在Stefan的帮助下。 I have changed the method both in JavaScript and PHP of data decleration so it will be easier to execute his solution. 我已经更改了JavaScript和PHP中的数据清除方法,因此执行他的解决方案会更容易。

PHP for loop: PHP for循环:

for($i = 0; $i < count($RFE_stands); $i++)
{
    $data = explode(":", $RFE_stands[$i]['image']);
    echo '"'."{$data[2]} (<a onmouseover='displayData({$i})' onmouseout='hideData({$i})' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id={$data[0]}'>{$data[0]}</a>) <br/><img onmouseover='displayData({$i})' onmouseout='hideData({$i})' src='https://www.ivao.aero/data/images/ratings/atc/{$data[3]}.gif' />".'",';
}

Actual Code: 实际代码:

<table id="atcOn" style="border-spacing: 20px 10px;">
<tr><td class='ATConline' onmouseover='displayData(0)' onmouseout='hideData(0)'><ul><li>LCCC_CTR</li><li id='0'> </li><li>122.800 Mhz</li></ul></td><td>LLBG_APP</td><td>LLBG_DEL</td></tr><tr><td>LLBG_E_GND</td><td>LLBG_TWR</td><td>LLBG_W_GND</td></tr><tr><td>LLLL_CTR</td><td>LLLL_FSS</td><td>LLSD_TWR</td></tr><tr></tr></table>
<script>
    var lastData = new Array();
    var data = new Array(
"Test Test (<a onmouseover='displayData(0)' onmouseout='hideData(0)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=390833'>390833</a>) <br/><img onmouseover='displayData(0)' onmouseout='hideData(0)' src='https://www.ivao.aero/data/images/ratings/atc/5.gif' />"," (<a onmouseover='displayData(1)' onmouseout='hideData(1)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(1)' onmouseout='hideData(1)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />"," (<a onmouseover='displayData(2)' onmouseout='hideData(2)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(2)' onmouseout='hideData(2)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />"," (<a onmouseover='displayData(3)' onmouseout='hideData(3)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(3)' onmouseout='hideData(3)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />"," (<a onmouseover='displayData(4)' onmouseout='hideData(4)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(4)' onmouseout='hideData(4)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />"," (<a onmouseover='displayData(5)' onmouseout='hideData(5)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(5)' onmouseout='hideData(5)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />"," (<a onmouseover='displayData(6)' onmouseout='hideData(6)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(6)' onmouseout='hideData(6)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />"," (<a onmouseover='displayData(7)' onmouseout='hideData(7)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(7)' onmouseout='hideData(7)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />"," (<a onmouseover='displayData(8)' onmouseout='hideData(8)' href='https://www.ivao.aero/Login.aspx?r=Member.aspx?Id=0'>0</a>) <br/><img onmouseover='displayData(8)' onmouseout='hideData(8)' src='https://www.ivao.aero/data/images/ratings/atc/.gif' />", "");

    function displayData(id)
    {
        lastData[id] = document.getElementById(id).innerHTML;
        document.getElementById(id).innerHTML = document.getElementById(id).innerHTML + data[id];
    }
    function hideData(id)
    {
        document.getElementById(id).innerHTML = lastData[id];
    }
</script>

http://jsfiddle.net/awaszgbs/ http://jsfiddle.net/awaszgbs/

Also to be noted that this code is pure HTML/JavaScript without the CSS and Jquery in my website. 还需要注意的是,此代码是纯HTML / JavaScript,而我的网站中没有CSS和Jquery。

Thanks for the help! 谢谢您的帮助!

I would advice to use more CSS code but thats a personal opinion. 我建议使用更多的CSS代码,但这是个人观点。 If you put the same onmouseover/out technique on your image, this would resolve the problem. 如果您在图像上使用相同的onmouseover / out技术,则可以解决此问题。 On the moment you put your mouse on the image, you are no longer on the td tag. 在将鼠标放在图像上的那一刻,您不再处于td标签上。

<img onmouseover='displayData(0)' onmouseout='hideData(0)'  src=" + imgURL + ".gif'>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 页面加载时鼠标置于图像上不会触发onmouseover事件 - Mouse positioned over image when page loads doesn't fire onmouseover event 当鼠标移过按钮时,如何使用onmouseover和onmouseout来隐藏和取消隐藏按钮? - How to use onmouseover and onmouseout to hide and unhide a button when the mouse goes over it? "鼠标悬停图像时显示图像" - Display image when mouse over image 没有 jquery 我需要确定鼠标是否在一个元素上,而不是确定它何时结束(以防它不移动以触发 onmouseover) - without jquery i need to find out if the mouse is over an element, not determine when it becomes over (in case it doesn't move to trigger onmouseover) 鼠标悬停时向文本添加文本 - Add text to image when mouse over 鼠标悬停时更改背景图像 - change background image when mouse over Javascript onmouseover事件可以正常工作,但需要在鼠标“不停”时反转 - Javascript onmouseover event working but need to reverse upon mouse “not over” 使div出现在onmouseover上,但是如果鼠标悬停在它上面则保留 - Make a div appear on onmouseover, but remain if the mouse hovers over it 在显示“ onmouseover”并将鼠标放在其上之后如何使div可见 - How to keep div visible after showing it with “onmouseover” and putting mouse over it onmouseover触发的功能可在鼠标悬停时不断触发 - onmouseover-triggered function keeps triggering on mouse over
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM