1. Subtraction of browser fans
0.1-0.01
0.02*3 -0.01
Need to keep two decimal places:
(The data obtained in the background already has two decimals, display the page; if there is no decimal, add decimals or round up)
function isDot(num) { var result = (num.toString()).indexOf("."); var length = num.toString().split(".")[1].length; if(result !== -1 && length == 2) { return num; } else { return num.toFixed(2); } }
2.div disable click
'pointer-events': 'none'
$('div').css({ 'background':'#ccc', 'pointer-events': 'none' });
3. End date cannot be greater than start date
var startTime = $('#startTime').val(); var endTime = $('#endTime').val(); if( startTime !== "" && endTime !== "" ){ if(new Date(startTime).getTime() > new Date(endTime).getTime()){ $('#endTime').val(""); bootbox.alert ( 'End time must be later than start time!' ); } }
4. The QR code will expire after 24 hours
var d=new Date(); //计算24小时 d.setTime(d.getTime()+ 24*60*60*1000); var year=d.getFullYear(); var month=change(d.getMonth()+1); var day=change(d.getDate()); var hour=change(d.getHours()); var minute=change(d.getMinutes()); var second=change(d.getSeconds()); function change(t){ if(t<10){ return "0"+t; }else{ return t; } } var time=year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second; $('.once span').html(time);
5. There is a return creation time, calculate whether the current time exceeds 24 hours
var d = new Date (); // Current timestamp var cZ = d.getTime () -data.createTime; if ( cZ > 24 * 60 * 60 * 1000 ) { return bootbox.alert ('The QR code is invalid ! ' ); };
6.html2canvas drawing screenshot
html part:
<a href="#" onclick="savePic();" data-toggle="modal" data-target="#myModal">保存图片</a> <!-Modal box (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;"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true" style="margin-right: 10px;">×</button> <h4 class = "modal-title" id = "myModalLabel" style = "text-align: center; font-weight: bold;"> Long press or screenshot to save the picture </ h4> </div> <div class="modal-body"> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div> <!-- /.modal -->
js part:
// Click to generate poster function 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 is the device pixel ratio }). 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. Regular judgment of mobile phone number (addition of paragraphs 16 and 19)
var telReg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/; if(!telReg.test($(".mobile").val())){ bootbox.alert ( 'The format of the mobile phone number is incorrect!' ); return ; }
8. Obtain the mobile phone number verification code and count down for 60 seconds
var countdown = 60 ; function settime(obj) { if (countdown == 0) { obj.removeAttribute("disabled"); obj.removeAttribute("class", "dis"); obj.setAttribute("class", "input"); obj.value = "Get verification code" ; countdown = 60; return; } else { obj.setAttribute("disabled", true); obj.setAttribute("class", "dis"); obj.value = "Resend (" + countdown + ")" ; countdown--; } setTimeout(function() { settime(obj); }, 1000) };
9. Scroll to the bottom, you can check the read statement
// Scroll bar to the bottom--I have read it and can check $ (". Content"). Scroll ( function () { var nScrollHight = $ ( this ) [0] .scrollHeight; // Total scrolling distance var nScrollTop = $ ( this ) [0] .scrollTop; // The current position to scroll to var nDivHight = $ (". content" ) .height (); if (nScrollTop + nDivHight> = nScrollHight) $("#radioShi").removeAttr('disabled'); });
// Check the radio function radioShi () { if ($ ("# radioShi"). Attr ("disabled") == "disabled" ) { return bootbox.alert ('Please read the contents of the electronic agreement!' ) ; } }
10. Time stamp conversion YMD h: m: s
function add0(m){ return m<10?'0'+m:m } function dates(timestamp){ var times = new Date(timestamp); 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(); return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s); }