js code small optimization

js code small optimization

It’s really a pit today, the boss took two days off. After he came, he gave pointers, but what they said was very good.

Finally, after completing the login and registration function of the nested small window, directly adjust the login and registration function written before, that is, the page jump

Not ajax asynchronous login

Say let change to ajax, return json format. That is to use @ResponseBody

Well, yes, change it, the freemarker value used directly on the page is also a problem, after all, the value of the ajax background model, put(); cannot be taken out.

After the solution, after all, the login and registration small window is an extracted html, and that page needs to be included directly.

OK. I think I think it's quite comprehensive, and I wrote a dead callback method after Ajax's success.

If you are too smart, the boss said that your writing is not perfect and needs to be optimized.

I'm blinded, what the hell.

The callback method is hard to write. Need to be flexible.

Well, yes, the final solution is to write a custom attribute data-seo="fff" in the <body>

Then pass var varf = $("body").data("seo"); in success

eval(varf+"()"); to make dynamic calls. The default implementation is

win.loc.reload()//page refresh. . .

It can be modified without affecting the source code. Or add it. . . ()
In place

The front-end page of a colleague I handed over to me is still using vue.js 
By default, a click event can be triggered by $("#id").trigger("click");
How to trigger v-on:click
$("#id")[0].dispatchEvent(new Event('click')); Well, it will be triggered after the object is acquired.
Struggle, Sao Nian. . .
<script type="text/javascript">
/* Mouse effects*/
var a_idx = 0;
jQuery(document).ready(function($) {
    $("body").click(function(e) {
        var a = new Array("❤Fuqiang❤","❤Democracy❤","❤Civilization❤","❤Harmony❤","❤Free❤","❤Equality❤","❤Justice❤","❤ Rule of Law ❤", "❤ patriotic ❤", "❤ Dedication ❤", "❤ Integrity ❤", "❤ Friendship ❤");
        var $i = $("<span></span>").text(a[a_idx]);
        a_idx = (a_idx + 1)% a.length;
        var x = e.pageX,
        y = e.pageY;
        $i.css({
            "z-index": 9999999999999999999999999999999999999999999999999999999999999999999999999,
            "top": y-20,
            "left": x,
            "position": "absolute",
            "font-weight": "bold",
            "color": "rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random( ))+")"
        });
        $("body").append($i);
        $i.animate({
            "top": y-180,
            "opacity": 0
        },
        1500,
        function() {
            $i.remove();
        });
    });
});
</script>
Reference: https://cloud.tencent.com/developer/article/1335865 js code optimization-cloud + community-Tencent Cloud