javascript - 鼠标悬停在 div 上时应该加载 javascript 文件

标签 javascript html

我有一个div :

<div class="content"></div>

这个div仅当我将鼠标悬停在 div 上时才会出现.

我有一个script.js应该仅在悬停此 div 时加载并且不是默认情况下。 这可能吗?

最佳答案

您可以使用 jQuery getScript 函数

$(function() { 
   $(".content").hover(function() {
       $.getScript( "script.js" );
   }); 
});

http://api.jquery.com/jquery.getscript/

关于javascript - 鼠标悬停在 div 上时应该加载 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20880926/

相关文章:

javascript - React hooks 改变 postMessage 的状态

javascript - requestPointerLock() 在 Vue.js 组件内部不起作用

jquery - 使用 WOW.js 与父 DIV 触发动画

php - 需要在 php 中将 $_FILES 转换为 $_POST

HTML-CSS : z-index not working with relative positions

html - 更改高度和宽度的元素中的垂直居中文本

javascript - 如果等于特定文本,则在页面上显示图像

javascript - 如何仅在 jQuery 中断开当前事件?

javascript - 正则表达式返回 javascript 变量

javascript - 附加左键或右键单击的事件监听器 - onclick 不适用于右键单击