Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery/Javascript-淡入div onclick淡出另一个';行不通_Javascript_Jquery_Html_Css_Onclick - Fatal编程技术网

jQuery/Javascript-淡入div onclick淡出另一个';行不通

jQuery/Javascript-淡入div onclick淡出另一个';行不通,javascript,jquery,html,css,onclick,Javascript,Jquery,Html,Css,Onclick,我想在点击一个div时弹出一个菜单,我在这个提琴中得到了所有的功能:但我无法在我的代码中实现它 HTML: jQuery: $("#clickOne").on('click', function() { $("#leafyPlants").fadeIn(); $("#juicyPlants").fadeOut(); }); $("#clickTwo").on('click', function() { $("#leafyPlants").fadeOut(); $("#

我想在点击一个div时弹出一个菜单,我在这个提琴中得到了所有的功能:但我无法在我的代码中实现它

HTML:

jQuery:

  $("#clickOne").on('click', function() {
   $("#leafyPlants").fadeIn();
   $("#juicyPlants").fadeOut();
});
$("#clickTwo").on('click', function() {
   $("#leafyPlants").fadeOut();
   $("#juicyPlants").fadeIn();
});
当我把它放在我的代码中时,它不会显示任何内容。

添加此css

<style>
img {
    float: left;
    display: block;
    height: 40px;
    width: 40px;
    cursor: pointer;
}
#img1 {
    background: #b00;
}
#img2 {
    background: #c00;
}
#div1 {
    display: none;
    position: absolute;
    top: 50px;
    width: 200px;
    background: #077;
    left: 10px;
}
#div2 {
    display: none;
    position: absolute;
    top: 50px;
    width: 200px;
    background: #0b0;
    left: 10px;
}
br {
    clear: both;
}
</style>

img{
浮动:左;
显示:块;
高度:40px;
宽度:40px;
光标:指针;
}
#img1{
背景:#b00;
}
#img2{
背景:#c00;
}
#第一组{
显示:无;
位置:绝对位置;
顶部:50px;
宽度:200px;
背景:#077;
左:10px;
}
#第二组{
显示:无;
位置:绝对位置;
顶部:50px;
宽度:200px;
背景:#0b0;
左:10px;
}
溴{
明确:两者皆有;
}
这是js代码

<script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<script>
$(document).ready(function(e) {
    $("#img1").on('click', function() {
   $("#div1").fadeIn();
   $("#div2").fadeOut();
});

$("#img2").on('click', function() {
   $("#div1").fadeOut();
   $("#div2").fadeIn();
});
});
</script>

$(文档).ready(函数(e){
$(“#img1”)。在('click',function()上{
$(“#div1”).fadeIn();
$(“#div2”).fadeOut();
});
$(“#img2”)。在('click',function()上{
$(“#div1”).fadeOut();
$(“#div2”).fadeIn();
});
});
你呢

<img id="img1"/> <img id="img2"/> <br/>
<div id="div1">1</div>
<div id="div2">2</div>


使用它可能会解决你的问题。

你有没有包括jquery库..?其实也没有听说过实现它。我是jquery新手。你没有那么努力。转到JQuery官方网站,看看如何包含JQuery。jquery.comIt工作正常检查演示:在我的网站上它不工作
<script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<script>
$(document).ready(function(e) {
    $("#img1").on('click', function() {
   $("#div1").fadeIn();
   $("#div2").fadeOut();
});

$("#img2").on('click', function() {
   $("#div1").fadeOut();
   $("#div2").fadeIn();
});
});
</script>
<img id="img1"/> <img id="img2"/> <br/>
<div id="div1">1</div>
<div id="div2">2</div>
<script src="http://code.jquery.com/jquery-1.11.0.js"></script>