1. Subtração dos fãs do navegador
0,1-0,01
0,02 * 3 -0,01
Precisa manter duas casas decimais:
(Os dados obtidos em segundo plano já possuem duas casas decimais, exibem a página; se não houver casas decimais, adicione casas decimais ou arredondar para cima)
função isDot (num) { var resultado = (num.toString ()). indexOf ("." ); var length = num.toString (). split (".") [1 ]. comprimento; if (resultado! == -1 && length == 2 ) { return num; } else { return num.toFixed (2 ); } }
2.div desativar clique
'pointer-events': 'none'
$ ('div' ) .css ({ 'background': '# ccc' , 'eventos-ponteiro': 'nenhum' });
3. A data final não pode ser maior que a data inicial
var startTime = $ ('# startTime' ) .val (); var endTime = $ ('# endTime' ) .val (); if (startTime! == "" && endTime! == "" ) { if ( new Date (startTime) .getTime ()> new Date (endTime) .getTime ()) { $ ( '#endTime'). Val ("" ); bootbox.alert ( 'O horário de término deve ser posterior ao horário de início!' ); } }
4. O código QR expirará após 24 horas
var d = nova data (); // 24. d.setTime (d.getTime () + 24 * 60 * 60 * 1000 ); var ano = d.getFullYear (); var mês = alteração (d.getMonth () + 1 ); var dia = alteração (d.getDate ()); var hora = mudança (d.getHours ()); var minute = alteração (d.getMinutes ()); var segundo = alteração (d.getSeconds ()); mudança de função (t) { if (t <10) { retornar "0" + t; } else { return t; } } var time = ano + '-' + mês + '-' + dia + '' + hora + ':' + minuto + ':' + segundo; $ ( '.once span'). html (hora);
5. Há um tempo de criação de retorno, calcule se o horário atual excede 24 horas
var d = new Date (); // Registro de data e hora atual var cZ = d.getTime () -data.createTime; if ( cZ > 24 * 60 * 60 * 1000 ) { retorna bootbox.alert ('o QR code é inválido ! ' ); };
6.html2canvas desenho screenshot
parte html:
<a href = "#" onclick = "savePic ();" data-toggle = "modal" data-target = "# myModal"> 图片 </a> <! - 模 态 框 (Modal) -> <div class = "modal fade" id = "myModal" tabindex = "-1" role = "dialog" aria-labelledby = "myModalLabel" aria-hidden = "true"> <div class = "modal-dialog" style = "margin: 0; padding: 5px;"> <div class = "modal-content"> <div class = "modal-header" style = "padding: 5px;"> <tipo de botão = "button" class = "close" data-descarte = "modal" aria-hidden = "true" style = "margin-right: 10px;"> × </button> </div> <! - /.modal-content -> </div> <! - /.modal-dialog -> </div> <! - /.modal ->
js parte:
// Clique para gerar a função de pôster savePic () { var capture = document.getElementById ('capture' ); var w = $ ('# capture' ) .width (); var h = $ ('# capture' ) .height ( ); html2canvas (capture, { allowTaint: true , taintTest: false , dpi: window.devicePixelRatio // window.devicePixelRatio é a proporção de pixels do dispositivo }). then ( function (canvas) { var dataUrl = canvas.toDataURL ("image / png ", 1,0 ), newImg= document.createElement ("img" ); newImg.src = dataUrl; newImg.style.width = w-50 ; newImg.style.height = h-50 ; console.log (newImg); $ ( '#myModal .modal-body' ) .empty (). append (newImg); }); }
7. Julgamento regular do número de telefone celular (aditamento aos parágrafos 16 e 19)
var telReg = / ^ [1] [3,4,5,6,7,8,9] [0-9] {9} $ / ; if (! telReg.test ($ (". mobile" ) .val ())) { bootbox.alert ( 'O formato do número do celular está incorreto!' ); return ; }
8. Obtenha o código de verificação do número de celular e faça a contagem regressiva por 60 segundos
var contagem regressiva = 60 ; função settime (obj) { if (contagem regressiva == 0 ) { obj.removeAttribute ( "disabled" ); obj.removeAttribute ( "classe", "dis" ); obj.setAttribute ( "classe", "entrada" ); obj.value = "获取 验证 码" ; contagem regressiva = 60 ; retorno ; } else { obj.setAttribute ( "desativado", verdadeiro ); obj."classe", "dis" ); obj.value = "重新 发送 (" + contagem regressiva + ")" ; contagem regressiva - ; } setTimeout ( function () { settime (obj); }, 1000 ) };
9. Role para baixo, você pode verificar a declaração de leitura
// Barra de rolagem até o final - eu li e posso verificar $ (". Content"). Scroll ( function () { var nScrollHight = $ ( this ) [0] .scrollHeight; // Distância total de rolagem var nScrollTop = $ ( this ) [0] .scrollTop; // Posição atual rolada para var nDivHight = $ (". content" ) .height (); if (nScrollTop + nDivHight> = nScrollHight) $ ( "#radioShi"). removeAttr ( 'disabled' ); });
// Verifique a função da função radioShi () { if ($ ("# radioShi"). attr ("disabled") == "disabled") { return bootbox.alert ('Por favor, leia o conteúdo do contrato eletrônico!' ); } }
10. Conversão de carimbo de data / hora YMD h: m: s
função add0 (m) { retornar m <10? '0' + m: m } datas da função (registro de data e hora) { var times = new Date (registro de data e hora); var y = times.getFullYear (); var m = times.getMonth () + 1 ; var d = times.getDate (); var h = times.getHours (); var mm = times.getMinutes (); var s = times.getSeconds (); retornar y + '-' + adicionar0 (m) + '-' + adicionar0 (d) + '' + adicionar0 (h) + ':' + adicionar0 (mm) + ':' + adicionar0 (s); }