javascript - 在 jquery 中定义和调用函数

标签 javascript jquery html css function

我正在尝试使用 jQuery 调用在外部 .js 中定义的函数,但没有任何反应。这是我的 html:

<head>
    <title>Página de pruebas jQuery</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!--<link rel="StyleSheet" href="css/style.css" type="text/css" />-->
    <script type="text/javascript" src="jquery-1.10.2.min.js" /></script>
    <script type="text/javascript" src="E1.js" />
    </script>
</head>

<body>
    <div id="contenedor">
        Pasa el ratón por aquí
    </div>

    <div id="mostrador" style="display: none;">
        Muy bien, has pasado el raton por encima!
    </div>
</body>

还有我的 jQuery 代码:

$(document).ready(function(){
    $("#contenedor").mouseenter(mostrarTexto(evento));

    $("#contenedor").mouseleave(ocultarTexto(evento));
});


    var mostrarTexto=function(evento){
        $("#mostrador").css("display","block");
    }

    var ocultarTexto=function(evento){
        $("#mostrador").css("display","none");
    }

我已经尝试了很多我搜索过的东西,但我无法让它工作

最佳答案

确保脚本文件(jQuery 库和 E1)已正确导入您的页面。

然后试试这个。

演示:http://jsfiddle.net/h9Veg/

$(document).ready(function(){
    $("#contenedor").mouseenter(function() { mostrarTexto(); });

    $("#contenedor").mouseleave(function() { ocultarTexto(); });
});


    var mostrarTexto=function(evento){
        $("#mostrador").css("display","block");
    }

    var ocultarTexto=function(evento){
        $("#mostrador").css("display","none");
    }

关于javascript - 在 jquery 中定义和调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21308720/

相关文章:

javascript - addEventListener 无故激活?

javascript - Windows 8 Metro 界面 - 是 IE10 吗?

javascript - 类似 JavaScript 中的 include() 函数

javascript - Contenteditable 高度过渡

html - int中每个数字的Angular4 : How do I *ngFor,?

php - 我想在 javascript 代码中调用 php 函数,但出现语法错误

javascript - 在新标签页中打开以进行打印

javascript - 如何使用同名元素的值

javascript - 如何在HTML中的输入文本框中添加span

javascript - angularjs无法将变量分配给html5视频src