【问题标题】:How to display a image from a table in a div when i mouse hover to the table row?当我将鼠标悬停到表格行时,如何在 div 中的表格中显示图像?
【发布时间】:2014-06-27 14:24:52
【问题描述】:

考虑一下我有两行的表。每行包含一些用户图像。 (实际上我已经使用 ajax 调用从 JSON 填充了表数据)。因此,当我将鼠标悬停到特定行时,它应该在 div 中显示该特定行图像。如何使用 jquery 实现这一点?

【问题讨论】:

    标签: jquery html json


    【解决方案1】:

    我认为您想在 div 中显示该图像。我已经在小提琴中解决了。 这是JsFiddle

    HTML 代码

    <table>
        <tr>
            <td><img src="http://www.mentoringminds.com/images/LinkedInIcon.png" alt="" /></td>
        </tr>
        <tr>
            <td><img src="https://cdn4.iconfinder.com/data/icons/pictype-free-vector-icons/16/view-256.png" alt="" /></td>
        </tr>
    </table>
    
    <div id="displayDiv">
        <img src="" alt=""/>
    </div>
    

    JS 代码

    $("td img").mouseover(function(){
        $("#displayDiv img").attr("src",$(this).attr("src"));
    });
    

    Hop,它可能会对你有所帮助。祝你今天过得愉快。 :)

    【讨论】:

    • 仅供参考,我已将用户图像存储在 JSON 文件中。
    • 如果它阻止了你,请投票并将答案标记为正确。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 2017-08-07
    相关资源
    最近更新 更多