jQuery實現倒計時(倒計時年月日可自己輸入)
683
2024-02-10
比起swfupload,uploadify插件配置使用都更簡單,只是剛加載的時候稍微慢了一秒左右.
廢話不多說了,直接給大家貼代碼了。
<html xmlns=”http://www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> <title>php jquery uploadify多文件上傳</title> <link href=”css/default.css” rel=”stylesheet” type=”text/css” /> <link href=”css/uploadify.css” rel=”stylesheet” type=”text/css” /> <script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script> <script type=”text/javascript” src=”js/swfobject.js”></script> <script type=”text/javascript” src=”js/jquery.uploadify.v2.1.0.min.js”></script> <script type=”text/javascript”> $(document).ready(function() { $(“#fileInput2″).uploadify({ ‘uploader': ‘js/uploadify.swf',//所需要的flash文件 ‘cancelImg': ‘cancel.png',//單個取消上傳的圖片 'script': ‘js/uploadify.php',//實現上傳的程序 ‘folder': ‘uploads',//服務端的上傳目錄 //'auto': true,//自動上傳 ‘multi': true,//是否多文件上傳 //'checkScript': ‘js/check.php',//驗證 ,服務端的 ‘displayData': 'speed',//進度條的顯示方式 //'fileDesc': ‘Image(*.jpg;*.gif;*.png)',//對話框的文件類型描述 //'fileExt': ‘*.jpg;*.jpeg;*.gif;*.png',//可上傳的文件類型 //'sizeLimit': 999999 ,//限制上傳文件的大小 //'simUploadLimit' :3, //并發上傳數據 //'queueSizeLimit' :5, //可上傳的文件個數 //'buttonText' :'文件上傳',//通過文字替換鈕扣上的文字 ‘buttonImg': ‘css/images/browseBtn.png',//替換上傳鈕扣 ‘width': 80,//buttonImg的大小 ‘height': 24,// ‘rollover': true,//button是否變換 onComplete: function (evt, queueID, fileObj, response, data) { //alert(“Successfully uploaded: “+fileObj.filePath); //alert(response); getResult(response);//獲得上傳的文件路徑 } //onError: function(errorObj) { // alert(errorObj.info+” “+errorObj.type); //} }); }); </script> <script type=”text/javascript”> function getResult(content){ //通過上傳的圖片來動態生成text來保存路徑 var board = document.getElementById(“divTxt”); board.style.display=””; var newInput = document.createElement(“input”); newInput.type = “text”; newInput.size = “45″; newInput.name=”myFilePath[]“; var obj = board.appendChild(newInput); var br= document.createElement(“br”); board.appendChild(br); obj.value=content; } </script> </head> <body> <fieldset style=”border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px 0″> <legend> <strong> 多文件上傳</strong></legend> <div> <input id=”fileInput2″ name=”fileInput2″ type=”file” /> <input type=”button” value=”確定上傳” onclick=”javascript:$(‘#fileInput2′).uploadifyUpload();”> || <a href=”javascript:$(‘#fileInput2′).uploadifyClearQueue();”>清除上傳列表</a></div> <p></p> </fieldset> <FORM name=”form2″ METHOD=POST ACTION=”db.php”> <div id=”divTxt” style=”display:none”><span style=”color:red”><strong>已經上傳的圖片有:</strong></span& gt;<br></div><br> <INPUT TYPE=”submit” value=”提 交”> </FORM> </body> </html>
ps:uploadify插件實現多個圖片上傳并預覽
使用uploadify插件可方便實現圖片上傳功能。兼容ie6、ie7。
上傳成功之后使用插件的回調函數讀取json數據,根據url實現圖片預覽。
效果圖:
點擊瀏覽文件上傳圖片,圖片依次在右側顯示預覽效果。
實現:
json數據格式如下:
頁面代碼如下:
注:需要引用jQuery.js、uploadify.js、uploadify文件。。uploadify文件下載地址:http://www.uploadify.com/download/
<html> <head> <script type="text/javascript" src="http://www.gimoo.net/t/1904/static/js/jquery.js">"></script> <script type="text/javascript" src="http://www.gimoo.net/t/1904/static/js/jquery.select.js">"></script> </head> <body> <div class="file-box"> <div id="divPreview"> <span style="float:left">(最多可上傳五張圖片)</span> </div> <input type="file" name="file" class="file" id="fileField" /> <input type="hidden" name="hash" id="hash" value="xoxo"/> </div> <script> $(function() { $("#fileField").uploadify({ 'height' : 30, 'swf' : '<?php echoYii::app()->request->baseUrl ?>/static/uploadify/uploadify.swf?var='+(newDate()).getTime(), 'uploader' :'index.php?r=upload/uploadimage', 'width' : 120, 'onUploadSuccess' : function(file, data, response) { var info = eval("("+data+")"); if(info.err==1){alert(info.msg);} //如果圖片過大或者格式錯誤彈出錯誤信息 else{ $("#divPreview").append($("<img src='http://www.gimoo.net/t/1904/5cbec0d92c858.html" + info.img + "'/>")); $("#divPreview").append($("<input type='hidden' name='imgId[]' value='" + info.imgId + "'/>")); } }, 'buttonText' : '瀏覽文件', 'uploadLimit' : 5, //上傳最多圖片張數 'removeTimeout' : 1, 'preventCaching': true, //不允許緩存 'fileSizeLimit' : 4100, //文件最大 'formData' : { '<?php echosession_name();?>' : '<?php echosession_id();?>','hash':$("#hash").val() } //hash }); $("#SWFUpload_0").css({ //設置按鈕樣式,根據插件文檔進行修改 'position' :'absolute', 'top': 20, 'left': 35, 'z-index' : 1 }); }); </script> </body> </html>
曾遇到問題:
ie、360瀏覽器中對json數據檢查比較嚴格,不允許最后一個“,”存在。其它瀏覽器不會報錯,需要注意。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!