jquery - bigktmbig/MyExperienceAlgorithm GitHub Wiki

======================================================stop href a Cachs 1: $(document).on('click', '#sidebar_menu ul.sub li a', function(e){ e.preventDefault(); var pathNm = $(this).attr('href'); _beforeLeaveAPage(function function_name() { // back to screen location.href = pathNm; }); }); cách 2: $(document).on('click', '#sidebar_menu ul.sub li a', function(e){ return false; }); $(document).on('click', '#sidebar_menu ul.sub li a.link', function(e){ var pathNm = $(this).data('path-name'); _beforeLeaveAPage(function function_name() { // back to screen location.href = pathNm; }); }); ================================================reset all value in div divParent.find(':input').each(function() { switch(this.type) { case 'password': case 'text': case 'textarea': case 'file': case 'select-one': case 'select-multiple': case 'date': case 'number': case 'tel': case 'email': $(this).val(''); break; case 'checkbox': case 'radio': this.checked = false; break; } }); ========================================scroll table header, body $('.table-body').on('scroll', function() { $('.table-header').scrollLeft($(this).scrollLeft()); }); =================================================== x-www-form-urlencoded 2019/10/28 let json ={data: {tensor: {values: ["football_player","6","name", "date", "age", "position", "years_in_toronto", "team", "player name","Date", "Age", "Position", "Years in Toronto", "School/Club Team","Average age of players in defence"]}}};

    $.ajax({
        type:'POST',
        url:'http://35.246.38.47:5000/predict',
        headers : {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        contentType: 'application/x-www-form-urlencoded; charset=utf-8',
        processData: false,
        data : 'json=' + JSON.stringify(json),
        success : (res)=>{
            console.log(res);
        },
        error : (e)=>{
            console.log(Error at : ${e})
        }           
    });

==============================================2019/02/12 datetimepicker bootstrap inorge input readonly

$('.datetimepicker1').datetimepicker({ locale: locale, format: 'YYYYMMDD', ignoreReadonly: true, }).on('dp.change', function(e){ if (e.oldDate !== null) { var newdate = new Date(e.date); var element = $(this).find('.month-current'); var year = newdate.getFullYear()*1; var month = newdate.getMonth()*1; if(month == 0) { year--; month = 12; } } });

===========================================2019/02/11 scroll from bottom to top const is_Mobile = !!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && !window.MSStream;

        if(is_Mobile) {
            $('#div_id').css('top','1500px');
            $('#div_id').animate({top: '0px'}, 350);
        }

===================================2019/01/04 : find element by class and data attribute $('.btn-reply[data-parent-id=' + parent_id + ']') ========================================2018/12/27 colorbox

  1. js: function showPopup(href, callback, width, height) { if(width == undefined || (window.innerWidth<900 && width.indexOf('px')!==-1) ){ width = '90%'; } if(height == undefined){ height = '90%'; } var properties = { href : href, open : true, iframe : true, fastIframe : false, opacity : 0.2, escKey : true, overlayClose : false, innerWidth : width, innerHeight : height, reposition : false, speed : 0, fixed: true, onOpen: function() { if (is_IOS) { var ycoord = $(window).scrollTop(); $('#colorbox').data('ycoord',ycoord); ycoord = ycoord * -1; $('body').css('position','fixed') .css('left','0px') .css('right','0px') .css('top',ycoord + 'px') .css('overflow', 'hidden'); } }, onComplete : function() {

         if (is_IOS) {
             widthWindow = $(window).width();
             widthColorBox = $('#colorbox').width();
             $('#colorbox').css('left', (widthWindow-widthColorBox)/2);
             // $('#colorbox').css('overflow', 'visible');
         }else {
             $('#colorbox-width').val(width);
             $('#colorbox-height').val(height);
         }
     },
     onClosed : function() {
         if (is_IOS) {
             $('body').css('position','')
             .css('left','auto')
             .css('right','auto')
             .css('top','auto')
             .css('overflow', 'auto'); 
             $(window).scrollTop($('#colorbox').data('ycoord')); 
         }
     	if (callback) {
     		callback();
     	}
     }
    

    }; $.colorbox(properties); }

  2. css: html,body{ -webkit-overflow-scrolling : touch !important; height: 100% !important; } ================================================ add custom method validation $(document).ready(function () { $.validator.addMethod("regex", function(value, element, regexpr) { return regexpr.test(value); }, "Please enter a valid email.");

    $("#register_form").validate({ // debug: true, rules: { "user[first_name]": {required: true}, "user[last_name]": {required: true}, "user[email]": {required: true, regex: /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/ }, "user[password]": {required: true, minlength: 8, maxlength: 20}, "user[password_confirmation]": {required: true, equalTo: "#password"} } }); });

hide modal $(document).on('hidden.bs.modal', function () { $('#image-gallery-image').attr('src', ""); });

scroll call ajax var loading = true; $(window).scroll(function(){ if(loading==true){ if(($(window).scrollTop()+$(window).height())>($('#container_categories').height() + 523)){} })

find and set value by class name $('#categories_filter_'+categories[i_jc]+' select.prices').on('change', function (evt) { $(this).parents('.freshspoke-header-section__filter_select').find('input.filter-pri').val(evt.target.selectedOptions[0].value); });

add/remove loading.gif when it's call ajax

  1. $(document).find('#categories_slider_'+cate).html('');
  2. $(document).find('#theImgProduct').remove();

find a class(ac, ad) in every class(ab) .js: $(".ab").eq([idx]); //idx is serial of ab class .html:

=========================================== multi click and excute with last click * JS: $(function() { var clickTimeout;

$('.plus').on('click', function() { clearTimeout(clickTimeout);

var oldVal = $('input').val();
var newVal = (parseInt($('input').val(),10) + 1);

$('input').val(newVal);

clickTimeout = setTimeout(function(){
    $('#output').text($('input').val()); // replace with your update code
}, 500);

}); });

  • HTML: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button type="button" class="plus">+</button> <input type="text" value="1"> <div>Updates on last click: <span id="output">1</span></div> =============================================2020/02/26 draft unsave data

.....input, textarea, select, ....
var oldDraft = $("#draft input, textarea, select").serialize(); var newDraft = $("#draft").data('serialize');
⚠️ **GitHub.com Fallback** ⚠️