首页 使用教程 正文内容

jquery 常用代码

哔哩 2023-10-23 19:10:06 使用教程 277
hover事件:
<script>
    $(function () {
    $(".pro_box a").hover(function(){
        $(".pro_box a img").eq($(this).index()).attr("src",$(".pro_box a").eq($(this).index()).attr("data-oimg"));
    },function(){
        $(".pro_box a img").eq($(this).index()).attr("src",$(".pro_box a").eq($(this).index()).attr("data-nimg"));
    });
    });
</script>
click事件:
<script>
    $(function () {
    $(".pro_box a").hover(function(){
        $(".pro_box a img").eq($(this).index()).attr("src",$(".pro_box a").eq($(this).index()).attr("data-oimg"));
    },function(){
        $(".pro_box a img").eq($(this).index()).attr("src",$(".pro_box a").eq($(this).index()).attr("data-nimg"));
    });
});
</script>
判断:
<script type="text/javascript">
    $(function () {
        var open = false;
        var first = true;
        if (first) {
            $("#open a i").addClass("icon-a-13Ashenglve");
            $("#open a i").removeClass("icon-guanbi");
            $(".mune").addClass("none");
            $("#cebian").css({ "background": "none", "width": "0", "height": "0", "top": "unset", "right": "0", "bottom": "0" });
            first = !first;
        }
        $("#cebian").click(function () {
            if (open) {
                $("#open a i").addClass("icon-a-13Ashenglve");
                $("#open a i").removeClass("icon-guanbi");
                $(".mune").addClass("none");
                $("#cebian").css({ "background": "none", "width": "0", "height": "0", "top": "unset", "right": "0", "bottom": "0" });
                open = !open;
            } else {
                $("#open a i").removeClass("icon-a-13Ashenglve");
                $("#open a i").addClass("icon-guanbi");
                $(".mune").removeClass("none");
                $("#cebian").attr("style", "");
                open = !open;
            }
        });
    });
</script>
微信二维码