twitter@js_bankfacebook@jsbankrss@jsbank






Efficace et utile JavaScript/jQuery Trucs et astuces Cette libre de HTML JavaScript tutorial fournit 45 + JavaScript/jQuery conseils et astuces qui vous aideront


�tiquette: d'

G�n�rez vos vid�os d'entreprise par l'IA avec la voix ou simplement du texte



Votre premi�re application vid�o AI GRATUITE ! Automatisez votre premi�re vid�o AI. Cr�ez votre vid�o professionnelle en 5 minutes gr�ce � l'IA. Aucun �quipement ni comp�tence en montage vid�o requis. Production vid�o sans effort pour les sp�cialistes du marketing de contenu.
Application vid�o AI ILLIMIT�E gratuite � port�e de main
  • Run a function 5 times with intervals of 20 seconds
  • 1.var count = 0;
    2.function myFunction() {
    3.    count++;
    4.    if(count > 5) clearInterval(timeout);
    5.    //do something
    6.}
    7.var timeout = setInterval(myFunction, 20000);
  • Check if an element exists
  • 1.if ($("#elementid").length) {
    2.    //it does!
    3.}
  • Cancel an ajax request
  • 01.var req = $.ajax({
    02.type:     "POST",
    03.url:     "someurl",
    04.data:     "id=1",
    05.success: function(){
    06.//something
    07.}
    08.});
    09.//Cancel the Ajax Request
    10.req.abort()
  • Check if cookies are enabled
  • 01.$(document).ready(function() {
    02.    var dt = new Date();
    03.    dt.setSeconds(dt.getSeconds() + 60);
    04.    document.cookie = "cookietest=1; expires=" + dt.toGMTString();
    05.    var cookiesEnabled = document.cookie.indexOf("cookietest=") != -1;
    06.    if(!cookiesEnabled){
    07.        //cookies are not enabled
    08.    }
    09.});
  • Toggle all checkboxes
  • 1.var tog = false; // or true if they are checked on load
    2.$('a').click(function() {
    3.    $("input[type=checkbox]").attr("checked",!tog);
    4.    tog = !tog;
    5.});
  • Get the index of an element
  • 1.$("ul > li").click(function () {
    2.    var index = $(this).prevAll().length;
    3.});
  • Validate date of birth
  • 01.$("#lda-form").submit(function(){
    02.    var day = $("#day").val();
    03.    var month = $("#month").val();
    04.    var year = $("#year").val();
    05.    var age = 18;
    06.    var mydate = new Date();
    07.    mydate.setFullYear(year, month-1, day);
    08. 
    09.    var currdate = new Date();
    10.    currdate.setFullYear(currdate.getFullYear() - age);
    11.    if ((currdate - mydate) < 0){
    12.        alert("Sorry, only persons over the age of " + age + " may enter this site");
    13.        return false;
    14.    }
    15.    return true;
    16.});
  • Test if an element is visible
  • 1.if($(element).is(":visible")) {
    2.    //The element is Visible
    3.}
  • Counting child elements
  • 01.<div id="foo">
    02.<div id="bar"></div>
    03.<div id="baz">
    04.<div id="biz">
    05.</div>
    06.<span><span>
    07.</div>
    08. 
    09.//jQuery code to count child elements
    10.$("#foo > div").length
  • Center an element on the screen
  • 01.jQuery.fn.center = function () {
    02.    this.css("position","absolute");
    03.    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    04.    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    05.    return this;
    06.}
    07. 
    08.//Use the above function as:
    09.$(element).center();

    Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web