假设cookie中存储的内容为:name=jack;password=123则在页面中获取变量username的值的JS代码如下:var username=document.cookie.split(";")[0].split("=")[1]; //JS操作cookies方法! //写cookies function setCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); }读取cookiesfunction getCookie(name) { var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

前端 2018-09-06

html demo<div id="headerMenu"> <ul> <li> <a href="/"> 首页</a> </li> <li> <a href="/info"> 信息</a> </li> </ul> </div>jqueryvar CURRENT_URL = window.location.href.split('#')[0].split('?')[0]; var SIDEBAR_MENU = $('#headerMenu'); // check active menu SIDEBAR_MENU.find('a[href="' + CURRENT_URL

前端 2018-09-05

思路:将图片base64值转换生成图片文件并保存,将图片保存路径转换成二维码。二维码的生成使用了phpqrcode类增加了一个删除的操作,传入开始和结束日期,删除该范围内生成的图片及二维码<?php //包含一个文件上传类中的上传类 header('Content-Type: text/html; charset=utf-8'); $content = file_get_contents("php://input"); $content = json_decode($content,true); $type = $content['type']; $errcode = 0; $errtext = ""; $myJson = array(); $savepath = 'static/upload/'; //保存base64图片目录 $qrpath = 'static/qrcode/

后端 2018-08-14

接收前端发送的文本,使用php内置函数实现文本转换图片<?php header('Content-Type: text/html; charset=utf-8'); $content = file_get_contents("php://input"); $content = json_decode($content,true); $type = $content['type']; $errcode = 0; $errtext = ""; $myJson = array(); $greetingpath = 'static/greeting/';//合成图片目录 $jsonfile = 'config.json';//语言合成config文件 $fontttf = "./static/dist/fonts/xiekai.ttf"; //文本字体

后端 2018-08-14

谷歌浏览器默认禁用了flash插件,所以要判断下浏览器是否禁用了flashfunction flashJudge(){ var flag = false; if(window.ActiveXObject){ try{ var swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); if(swf){ flag = true; } }catch(e){ } }else{ try{ var swf = navigator.plugins['Shockwave Flash']; if(swf){ flag = true; } }catch(e){ } } if(flag){

前端 2018-07-24

丢弃小数部分,保留整数部分parseInt(5/2) ```` 向上取整,有小数就整数部分加1 ====Math.ceil(5/2) 四舍五入 ==== ```javascript Math.round(5/2)向下取整Math.floor(5/2)

前端 2018-07-23

html demo<input id="checkboxID" type="checkbox" value="imxgr" />javascript写法if(document.getElementById("checkboxID").checked){ alert("checkbox is checked"); }jquery写法$("input[type='checkbox']").attr('value') 返回结果:imxgr $("input[type='checkbox']").is(':checked') 返回结果:选中=true,未选中=false

前端 2018-07-20

javascript写法获取值var obj = document.getElementById("testSelect"); //定位id var index = obj.selectedIndex; // 选中索引 var text = obj.options[index].text; // 选中文本 var value = obj.options[index].value; // 选中值jquery写法获取值$('#testSelect option:selected').text();//选中的文本 $('#testSelect option:selected') .val();//选中的值 $("#testSelect ").get(0).selectedIndex;//索引 或 $("#tesetSelect").find("option:selected").text();//选中的文本 $("#tesetSelect").find(

前端 2018-07-20