js json 提交

来源:互联网 发布:哪个剪辑软件最快 编辑:程序博客网 时间:2024/04/30 00:57
 <script type="text/javascript" language="javascript">   var random;  var ids; //添加文件 监听 function addRow(){var rom=changeRandom();var txt2=getFileText();var  divfilelist = document.getElementById("divfilelist");var f = document.createElement('div');f.setAttribute("id","f"+rom);var input = document.createElement('span');input.setAttribute("id","p"+rom);input.innerHTML =txt2;f.appendChild(input);var status = document.createElement('span');status.innerHTML ='开始上传中.......>>>';status.setAttribute("class","status");status.setAttribute("id","s"+rom);f.appendChild(status);var a = document.createElement('a');a.innerHTML ='>>>del>>>';a.setAttribute("class","status");a.setAttribute("id","a"+rom);a.setAttribute("href","#");a.setAttribute("onClick","delFile("+rom+")");f.appendChild(a);divfilelist.appendChild(f);ids=rom;subfile();}//获得10位数 随机数function changeRandom(){var random=''+Math.random();return random.substr((random.length-10),random.length);}function changeTxt(id,txt){document.getElementById(id).innerHTML=txt;}function getFileText(){ var id=document.getElementById("idfileName")        var obj=id.value;                var aa=obj.split('\\');            //var txt=aa[aa.length-1];  //jpg 结果        var txt=obj.substr((obj.lastIndexOf('\\')+1),obj.length);        return txt;}function FileUpload_onselect()        {        var id=document.getElementById("idfileName")        var obj=id.value;                var aa=obj.split('\\');            //var txt=aa[aa.length-1];  //jpg 结果        var txt=obj.substr((obj.lastIndexOf('\\')+1),obj.length);      id.value=txt;        }        function delFile(id){$("#f"+id).remove();$("#s"+id).remove();$("#p"+id).remove();$("#a"+id).remove();//清除掉之前的//var idfileName=document.getElementById("idfileName");//idfileName.value='';}// 浏览器 类型function checkBrowser() {  var ug = navigator.userAgent.toLowerCase();    var browserType = "";  var ver = "";    //检测IE及版本  var IE = ug.match(/msie\s*\d\.\d/); //提取浏览器类型及版本信息,注match()方法返回的是数组而不是字符串  var isIE = check(/msie/);  if(isIE) {   browserType = "Internet Explorer";     }    //检测chrome及版本  var chrome = ug.match(/chrome\/\d\.\d/gi);  var isChrome = check(/chrome/);  if(isChrome) {   browserType = "Chrome";     }    //检测firefox及版本  var firefox = ug.match(/firefox\/\d\.\d/gi);  var isFirefox = check(/firefox/);  if(isFirefox) {   browserType = "Firefox";    }  return browserType;   } function check(reg) {  var ug = navigator.userAgent.toLowerCase();  return reg.test(ug); }     </script><script type="text/javascript">//文件上传 后台function subfile() {changeText("#"+ids,"start上传中....");var p = $("#idfileName").val();//var ju=judgeBrows();alert('safd'+checkBrowser());$.ajax( { type : "post",  dateType:'text',         data: "fileupload="+p+"&random="+ids,//提交表单,相当于, url : "<%=basePath%>tvs/dealUploadFile.action",success : update_page ,error : function(msg) {changeText("#s"+ids,"上传失败..");//changeText("#result","上传失败..");}});}function changeText(re,str){$(re).text(str); }//参数obj为input file对象function update_page(info){ var json=eval(info); var str=json.info;  changeText("#s"+ids,str);}</script>

0 0
原创粉丝点击