javascript - 激活多个 id jQuery

标签 javascript jquery

我想要多个 div id 来启动这个动画。为什么这不起作用?

我的意思是:

$("#treest, #treest2, #treest3").click(function() {
    anim10();
});

这是完整的代码

 /** ANIMATE DropDown  */
var $a = $("#navigation"),
$b = $(".mainNavitem:eq(1)"),
$c = $(".c");

function anim1() {
$b.animate({width: 395}, {duration: 300, complete: anim2});
}

function anim2() {
$a.animate({top:"70px"}, {duration: 400});
$c.animate({top:"70px"}, {duration: 400});
}

$("#mains").click(function() {
anim1();
});

function anim10() {
$c.animate({top:"0px"}, {duration: 200});
$a.animate({top:"0px"}, {duration: 200 , complete: anim20});
}

function anim20() {
$b.animate({width: 80}, {duration: 200});
}

$("#treest, #treest2, #treest3").click(function() {
anim10();
});

你知道我该如何解决这个问题吗?

编辑:

Fiddle Demo

最佳答案

您是否使用 $(document).ready() 事件运行代码?喜欢

jQuery(function(){
    $("#mains").click(function() {
        anim1();
    });

    $("#treest, #treest2, #treest3").click(function() {
        anim10();
    });
})

关于javascript - 激活多个 id jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21110384/

相关文章:

javascript - 如何强制下载未使用的 CSS 图像?

javascript - 查找两个 div 标签之间的 p 标签

javascript - 来自一个 Vue 组件的数据影响另一个组件

javascript - 你将如何移动一个完整的 backbone.js 树?

javascript - ajax 加载中拒绝访问 (Grails)

jQuery UI 对话框中的 jQuery Validate 远程方法仅有效一次

javascript - Sails.js 与 React.js,如何正确做?

javascript - 在警告框中显示数组内容

javascript - selectionStart-End with textareas

Javascript 使用 foreach 函数添加新行