jQuery显示和隐藏不起作用?缺少某些东西,我无法弄清楚 [英] Jquery Show and Hide doesnt work? Something is missing and i can't figure it out
本文介绍了jQuery显示和隐藏不起作用?缺少某些东西,我无法弄清楚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
<!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">
$(".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>
当我在 http://jsfiddle.net/ppksR/中尝试时,它确实有效,但是当我将其粘贴到我的Dreamweaver中,无法正常工作.我错过了什么???有帮助吗?
when i try it in http://jsfiddle.net/ppksR/, it's really working but when i copy paste it in my dreamweaver, its not working. What did i miss??? Any help?
推荐答案
jsfiddle将JavaScript代码包装在onLoad
中,您应该这样做.将脚本内容包装在:
jsfiddle is wrapping the JavaScript code in onLoad
, which you should do. Wrap the script contents in:
$(function () {
// your code
});
要让jsfiddle模拟您在做什么,请将onLoad
更改为No wrap - in <head>
To have jsfiddle emulate what you are doing, change the onLoad
to No wrap - in <head>
这篇关于jQuery显示和隐藏不起作用?缺少某些东西,我无法弄清楚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文