html代码:
<input type="file" name="file" id="file" class="input_text80"></input>
js:
方法一:字符串截取
var file = $("#file").val();
var fileName = getFileName(file);
function getFileName(o){
var pos=o.lastIndexOf("\\");
return o.substring(pos+1);
}
方法二:正则表达式
var file = $("#file").val();
var strFileName=file.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1"); //正则表达式获取文件名,不带后缀
var FileExt=file.replace(/.+\./,""); //正则表达式获取后缀
#2034
#2035
#2036
#2037
#2038
#2039
#2040
#2041
#2042
$(document).height() == $(window).height() + $(window).scrollTop()
当网页高度不足浏览器窗口时$(document).height()返回的是$(window).height()
$("body").height():body可能会有边框,获取的高度会比$(document).height()小;
$("html").height():在不同的浏览器上获取的高度的意义会有差异,说白了就是浏览器不兼容。
$(window).height()值有问题,返回的不是浏览器窗口的高度?
原因:网页没有加上<!DOCTYPE>声明。
#2043
alert($(window).height()); //浏览器当前窗口可视区域高度 alert($(document).height()); //浏览器当前窗口文档的高度 alert($(document.body).height());//浏览器当前窗口文档body的高度 alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin alert($(window).width()); //浏览器当前窗口可视区域宽度 alert($(document).width());//浏览器当前窗口文档对象宽度 alert($(document.body).width());//浏览器当前窗口文档body的高度 alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin
#2044
原因:滚动固定的时候,原来的菜单导航高度0不在文档流里面,导致文档高度变化变小减去文档流外的后固定导航栏
#2045
html代码: <input type="file" name="file" id="file" class="input_text80"></input> js: 方法一:字符串截取 var file = $("#file").val(); var fileName = getFileName(file); function getFileName(o){ var pos=o.lastIndexOf("\\"); return o.substring(pos+1); } 方法二:正则表达式 var file = $("#file").val(); var strFileName=file.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1"); //正则表达式获取文件名,不带后缀 var FileExt=file.replace(/.+\./,""); //正则表达式获取后缀
#2046
第一种方法:
var timestamp = Date.parse(new Date()); 结果:1280977330000
第二种方法:
var timestamp = (new Date()).valueOf(); 结果:1280977330748
第三种方法:
var timestamp=new Date().getTime(); 结果:1280977330748
第一种:获取的时间戳是把毫秒改成000显示,
第二种和第三种是获取了当前毫秒的时间戳。
#2047
http://qiniuphotos.qiniudn.com/gogopher.jpg?download/test.jpg
#2048
<?php require_once 'vendor/autoload.php'; header('Access-Control-Allow-Origin:*'); use Qiniu\Auth; $bucket = 'wailian'; $accessKey = ''; $secretKey = ''; $auth = new Auth($accessKey, $secretKey); //$upToken = $auth->uploadToken($bucket); $policy = array( 'returnUrl' => 'http://pan.lizhenqiu.com/fileinfo.php', 'returnBody' => '{"fname": $(key)}', ); $upToken = $auth->uploadToken($bucket, null, 3600, $policy); ?><!DOCTYPE html> <html> <head> <title>公盘 -lizhenqiu.com</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="format-detection" content="telephone=no" /> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.0/jquery.min.js"></script> <script type="text/ecmascript" src="md5.js"></script> <style>@supports (display:none) { dot { display: inline-block; width: 3ch; text-indent: -1ch; vertical-align: bottom; overflow: hidden; animation: dot 3s infinite step-start both; /* 等宽字体很重要 */ font-family: Consolas, Monaco, monospace; } } @keyframes dot { 33% { text-indent: 0; } 66% { text-indent: -2ch; } }</style></head> <body> <p>请填写标题、简介、选择要上传的RAR文件包</p> <div id="ddimgupoloing" style="display:none;color: red;">正在上传文件<dot>...</dot></div> <form id="myform" autocomplete="off" name="myform" onsubmit="return check();" method="post" action="http://up.qiniu.com" enctype="multipart/form-data"> <input name="key" id="key" type="hidden" value=""> <input name="token" type="hidden" value="<?php echo $upToken;?>"> <p><input name="title" type="text" autocomplete="off" id="intitle" placeholder="请填写标题" /></p> <p><input name="jianjie" type="text" autocomplete="off" id="injianjie" placeholder="请填写简介" /></p> <p><input name="file" autocomplete="off" id="f" type="file" style=" background: #eee; border: 1px solid #eee; border-right: 1px solid #000; " /></p> <input type="submit" value="Submit" style="display:none;" /> </form><script type="text/javascript"> function asq(title,jianjie,durl,types){ $.ajax( { url: '/up.php?title='+title+'&jianjie='+jianjie+'&durl='+durl+'&types='+types, //这里是静态页的地址 type: "GET", //静态页用get方法,否则服务器会抛出405错误 //dataType: "json", //cache: false, //async: false, beforeSend: function(){ // Handle the beforeSend event }, success: function(data){ //var result = $(data).find("另一个html页面的指定的一部分").html(); return true; } }); return false; } function check(){ var s=$('#f').val(); var injianjie=$('#injianjie').val(); var intitle=$('#intitle').val(); if(!intitle){ //alert('请填写标题'); //location.href = '/out.php'; var strFileName=s.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1"); $('#intitle').val(strFileName); timedMsg(); return false; } if(!injianjie){ //alert('请填写简介'); var strFileName=s.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1"); $('#injianjie').val(strFileName); timedMsg(); //location.href = '/out.php'; return false; } var types=selectFile(document.getElementById("f")); //alert(s); var h=$('#key').val(); if(!s || h) return false; var timestamp = Date.parse(new Date()); var hash = hex_md5(s)+timestamp; $('#key').val(hash); asq(intitle,injianjie,hash,types); } function selectFile(input) { var fileName = input.value; if(fileName.length > 1 && fileName ) { var ldot = fileName.lastIndexOf("."); var type = fileName.substring(ldot + 1); return type; if(type != "rar") { alert('请上传rar压缩包文件'); location.href = '/out.php'; //清除当前所选文件 input.outerHTML=input.outerHTML.replace(/(value=\").+\"/i,"$1\""); return false; } } return false; //return true; } function timedMsg() { var s=$('#f').val(); if(s){ check(); var h=$('#key').val(); if(h){ $('#myform').css('display','none'); $('#ddimgupoloing').css('display',''); document.getElementById("myform").submit(); } return false; } setTimeout("timedMsg()",1000); } setTimeout("timedMsg()",3000); </script> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- blog --> <ins class="adsbygoogle" style="display:inline-block;width:320px;height:100px" data-ad-client="ca-pub-7446801070784593" data-ad-slot="7895142255"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </body> </html>
#2049
上传策略的callbackBody字段设置fsize这个魔法变量即可:
http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#magicvar
php的话就是生成token的地方
$bucket = Config::BUCKET_NAME; $accessKey = Config::ACCESS_KEY; $secretKey = Config::SECRET_KEY; $auth = new Auth($accessKey, $secretKey); $policy = array( 'callbackUrl' => 'http://172.30.251.210/callback.php', 'callbackBody' => '{"fname":"$(fname)","fsize":"$(fsize)","fkey":"$(key)","desc":"$(x:desc)","uid":' . $uid . '}' ); $upToken = $auth->uploadToken($bucket, null, 3600, $policy); header('Access-Control-Allow-Origin:*'); echo $upToken;
#2050
<a href="javascript: alert('test');">
#2051
#2052
<script type="text/javascript" src="http://api.map.baidu.com/api?type=quick&ak=X8u8xx9GzO88EIydfLbTsvbK&v=1.0"></script> <!---------------------------------- 地图开始 ----------------------------------> <div class="lxfsditu" id="map" style="border:1px solid #ccc; width:15rem; height:11.85rem;"> </div> <!---------------------------------- 地图结束 ----------------------------------> <script type="text/javascript"> // 百度地图API功能 var map = new BMap.Map("map"); map.centerAndZoom(new BMap.Point(108.312475,22.772913), 14); map.addControl(new BMap.ZoomControl()); //添加地图缩放控件 var marker1 = new BMap.Marker(new BMap.Point(108.312475,22.772913)); //创建标注 map.addOverlay(marker1); // 将标注添加到地图中 //创建信息窗口 var infoWindow1 = new BMap.InfoWindow("广西天材医疗器械有限公司<br>南宁市金凯路11号荣港城二期12座16楼E号"); marker1.addEventListener("click", function(){this.openInfoWindow(infoWindow1);}); </script>