【问题标题】:what is the correct Jquery document.ready wrap什么是正确的 Jquery document.ready wrap
【发布时间】:2013-03-04 01:50:33
【问题描述】:

我正在尝试在下面的代码中复制其他用户正在执行的操作:

Jquery Show and Hide doesnt work? Something is missing and i can't figure it out

但就像她一样,我也被卡住了,因为它在 Dreamweaver 中不起作用。我想我没有通过添加正确的包装正确地做到这一点。知道的人可以指出或编辑我的脚本吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>



<script type="text/javascript">
jQuery(document).ready(function($) 
{
    $(".social").hover(function() 
    {
        $("h1", this).hide();
        $(".networks", this).fadeIn();
    }, 
    function() 
    {
        $(".networks", this).hide();
        $("h1", this).fadeIn();
    });
});
</script>

<style>
.networks 
{
    display:none;
}
</style>
</head>

<body>
<div class="social">
    <h1>Share this</h1>
    <div class="networks">
        <p>Twitter</p>
        <p>Facebook</p>
    </div>
</div>      

</body>
</html>

【问题讨论】:

标签: jquery document-ready


【解决方案1】:

你可以参考正确的地址:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

【讨论】:

  • @etangnal,我知道。在其他一些 jquery 脚本上,它确实可以完美运行,但在这种情况下却不是。这很奇怪。
  • 这可能是 Dreamweaver 的问题,因为这个小提琴:jsfiddle.net/zAeFe/1 可以正常工作。请参阅@DarthTux 的评论。
  • 我认为这不是织梦者。只是 jsfiddle 在没有正确的函数包装的情况下运行它。在 Dreamweaver 中,您需要添加正确的包装。
【解决方案2】:

确保您使用网络服务器(wamp 或 xampp)进行测试。 如果您想在没有网络服务器的情况下对其进行测试,请下载 jquery 库并将其包含在本地

正确的换行是:

$(document).ready(function() {
    $(".social").hover(function() {
        $("h1", this).hide();
        $(".networks", this).fadeIn();
    }, function() {
        $(".networks", this).hide();
        $("h1", this).fadeIn();
    });
})

$(function() {
    $(".social").hover(function() {
        $("h1", this).hide();
        $(".networks", this).fadeIn();
    }, function() {
        $(".networks", this).hide();
        $("h1", this).fadeIn();
    });
})

【讨论】:

    猜你喜欢
    • 2016-10-07
    • 1970-01-01
    • 2016-01-12
    • 2011-06-12
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    相关资源
    最近更新 更多