1.介绍了JS数组合并push与concat区别,结合实例形式分析了javaScript中针对数组合并操作使用push与concat的区别,需要的朋友可以参考下
var arr = [];arr.push(1);arr.push([2, 3]);arr.push(4, 5);arr = arr.concat(6);arr = arr.concat([7, 8]);arr = arr.concat(9, 10);arr.each(function(index, value){ alert(value);});结果
12,345678910差异 push 遇到数组参数时,把整个数组参数作为一个元素;而 concat 则是拆开数组参数,一个元素一个元素地加进去。 push 直接改变当前数组;concat 不改变当前数组。
3.Ajax文件下载
<script type="text/Javascript"> function DownLoad(strUrl) { var form = $("<form>"); //定义一个form表单 form.attr('style', 'display:none'); //在form表单中添加查询参数 form.attr('target', ''); form.attr('method', 'post'); form.attr('action', "/QuestionInfo/DowmLoad"); var input1 = $('<input>'); input1.attr('type', 'hidden'); input1.attr('name', 'strUrl'); input1.attr('value', strUrl); $('body').append(form); //将表单放置在web中 form.append(input1); //将查询参数控件提交到表单上 form.submit(); } </script>后台代码 #region 文档下载 /// <summary> /// 文件下载函数 /// </summary> /// <param name="fileUrl"></param> /// <returns></returns> [HttpPost] public void DowmLoad(string strUrl) { try { string fullPathUrl = Server.MapPath(strUrl);//获取下载文件的路劲 System.IO.FileInfo file = new System.IO.FileInfo(fullPathUrl); if (file.Exists)//判断文件是否存在 { Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.AddHeader("content-disposition", "attachment;filename=" + file.Name); Response.AddHeader("cintent_length", "attachment;filename=" + HttpUtility.UrlDecode(file.Name)); Response.AddHeader("cintent_length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName);//通过response对象,执行下载操作 Response.Flush(); Response.End(); } } catch(Exception e) { Console.Write(e.ToString()); } }4.jQuery 遍历函数包括了用于筛选、查找和串联元素的方法。
复制代码 var arr = [ "one", "two", "three", "four"]; $.each(arr, function(){ alert(this); }); //上面这个each输出的结果分别为:one,two,three,four var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9]] $.each(arr1, function(i, item){ alert(item[0]); }); //其实arr1为一个二维数组,item相当于取每一个一维数组, //item[0]相对于取每一个一维数组里的第一个值 //所以上面这个each输出分别为:1 4 7 var obj = { one:1, two:2, three:3, four:4}; $.each(obj, function(i) { alert(obj[i]); }); //这个each就有更厉害了,能循环每一个属性 //输出结果为:1 2 3 4<html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){ $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); });});</script></head><body><button>输出每个列表项的值</button><ul><li>Coffee</li><li>Milk</li><li>Soda</li></ul></body></html>$(function(){ var arr = []; $(":checkbox").each(function(index){ arr.push(this.id); }); var str = arr.join(","); alert(str);})$(function(){ var str = $(":checkbox").map(function() { return this.id; }).get().join(); alert(str);})JS函数的参数(arguments)的使用
function Test(a, b){var i, s = "Test函数有";var numargs = arguments.length; // 获取实际被传递参数的数值。var expargs = Test.length; // 获取期望参数的数值,函数定义时的预期参数个数(有a和b 2个参数)。s += (expargs + "个参数。");s += "/n/n"for (i =0 ; i < numargs; i++){ // 获取参数内容。s += " 第" + i + "个参数是:" + arguments[i] + "/n";}return(s); // 返回参数列表。}alert(Test('param1','second param','第三个参数'));<html> <head> <script language="javascript"> function reloadList(){ if(typeof arguments[0] == "function"){ arguments[0].call(this); arguments[0](); } if(typeof arguments[0] == "string") alert(arguments[0]); if(typeof arguments[0] == "number") alert(arguments[0]); if(typeof arguments[0] == "undefined") alert(arguments[0]); if(typeof arguments[0] == "boolean") alert(arguments[0]); if(typeof arguments[0] == "null") alert(arguments[0]); } reloadList(function(){}); </script> </head> <body> </body>新闻热点
疑难解答