js笔记
本文主要记录本人使用js中的一些笔记
1.<a href="javascript:void(0);" onclick='add("tb1")'>
2.动态添加表单
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/** * 动态添加上传表单 * */ function add_upload_form(tableId, userId, upToken) { console.log('add_upload_form'); upToken = "5N1L2z_at_JxxDzkht2vJMYmc72mf8Y03-5bK4xl:H_7Y-mJ4th38heNo0zs8EnDjskI=:eyJzY29wZSI6InR1b21hLXRlc3QiLCJkZWFkbGluZSI6MTM4MjY4ODY2OH0="; var currentMillis = new Date().getTime(); // //105/2013-07-21/1374399378070.jpg var keyValue = userId + "/" + currentMillis + ".jsp"; console.log('key:', keyValue); var uploadForm = document.createElement("form"); // 一定要加入到body中!! document.body.appendChild(uploadForm); uploadForm.method = 'post'; uploadForm.action = 'http://up.qiniu.com/'; uploadForm.enctype = 'multipart/form-data'; formId = formIdPrefix + (++uploadForm_id); console.log('function',formId); uploadForm.setAttribute("id",formId); // uploadForm.target = 'actionframe'; // input file var inputFile = document.createElement("input"); inputFile.setAttribute("name", "file"); inputFile.setAttribute("type", "file"); uploadForm.appendChild(inputFile); // key var key = document.createElement("input"); key.setAttribute("name", "key"); key.setAttribute("type", "hidden"); key.setAttribute("value", keyValue); uploadForm.appendChild(key); //upload token var token = document.createElement("input"); token.setAttribute("name", "token"); token.setAttribute("type", "hidden"); token.setAttribute("value", upToken); uploadForm.appendChild(token); //上传按钮 var submitBtn = document.createElement("input"); submitBtn.setAttribute("name", "upload"); submitBtn.setAttribute("type", "submit"); submitBtn.setAttribute("value", "上传"); uploadForm.appendChild(submitBtn); };
3.input type为file的上传,取消上传
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<input type='file' id='file_upload_1'> var obj = document.getElementById('file_upload_1') ; obj.outerHTML=obj.outerHTML;