collectgarbage(CollectGarbage)

http://www.itjxue.com  2023-02-15 08:41  来源:未知  点击次数: 

怎么获取触发事件的元素

事件源对象

event.srcElement.tagName(document.getElementsByTagName)

event.srcElement.type

捕获释放

event.srcElement.setCapture();

event.srcElement.releaseCapture();

事件按键

event.keyCode

event.shiftKey

event.altKey

event.ctrlKey

事件返回值

event.returnValue

鼠标位置

event.x

event.y

窗体活动元素

document.activeElement

绑定事件

document.captureEvents(Event.KEYDOWN);

访问窗体元素

document.all("txt").focus();

document.all("txt").select();

窗体命令

document.execCommand

窗体COOKIE

document.cookie

菜单事件

document.oncontextmenu

创建元素

document.createElement("SPAN");

根据鼠标获得元素:

document.elementFromPoint(event.x,event.y).tagName=="TD

document.elementFromPoint(event.x,event.y).appendChild(ms)

窗体图片

document.images[索引]

窗体事件绑定

document.onmousedown=scrollwindow;

元素

document.窗体.elements[索引]

对象绑定事件

document.all.xxx.detachEvent('onclick',a);

插件数目

navigator.plugins

取变量类型

typeof($js_libpath) == "undefined"

下拉框

下拉框.options[索引]

下拉框.options.length

查找对象

document.getElementsByName("r1");

document.getElementById(id);

定时

timer=setInterval('scrollwindow()',delay);

clearInterval(timer);

UNCODE编码

escape() ,unescape

父对象

obj.parentElement(dhtml)

obj.parentNode(dom)

交换表的行

TableID.moveRow(2,1)

替换CSS

document.all.csss.href = "a.css";

并排显示

display:inline

隐藏焦点

hidefocus=true

根据宽度换行

style="word-break:break-all"

自动刷新

meta HTTP-EQUIV="refresh" CONTENT="8;URL="

简单邮件

a href="mailto:aaa@bbb.com?subject=cccbody=xxxyyy"

快速转到位置

obj.scrollIntoView(true)

a name="first"

a href="#first"anchors/a

网页传递参数

location.search();

可编辑

obj.contenteditable=true

执行菜单命令

obj.execCommand

双字节字符

/[^\x00-\xff]/

汉字

/[\u4e00-\u9fa5]/

让英文字符串超出表格宽度自动换行

word-wrap: break-word; word-break: break-all;

透明背景

IFRAME src="1.htm" width=300 height=180 allowtransparency/iframe

获得style内容

obj.style.cssText

HTML标签

document.documentElement.innerHTML

第一个style标签

document.styleSheets[0]

style标签里的第一个样式

document.styleSheets[0].rules[0]

防止点击空链接时,页面往往重置到页首端。

a href="javascript:function()"word/a

上一网页源

asp:

request.servervariables("HTTP_REFERER")

javascript:

document.referrer

释放内存

CollectGarbage();

禁止右键

document.oncontextmenu = function() { return false;}

禁止保存

noscriptiframe src="*.htm"/iframe/noscript

禁止选取body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()

禁止粘贴

input type=text onpaste="return false"

地址栏图标

link rel="Shortcut Icon" href="favicon.ico"

favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下

收藏栏图标

link rel="Bookmark" href="favicon.ico"

查看源码

input type=button value=查看网页源代码 onclick="window.location = 'view-source:'+ ''"

关闭输入法

input style="ime-mode:disabled"

自动全选

input type=text name=text1 value="123" onfocus="this.select()"

ENTER键可以让光标移到下一个输入框

input onkeydown="if(event.keyCode==13)event.keyCode=9"

文本框的默认值

input type=text value="123" onfocus="alert(this.defaultValue)"

title换行

obj.title = "123 sdfs "

获得时间所代表的微秒

var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()

窗口是否关闭

win.closed

checkbox扁平

input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"br

获取选中内容

document.selection.createRange().duplicate().text

自动完成功能

input type=text autocomplete=on打开该功能

input type=text autocomplete=off关闭该功能

窗口最大化

body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)"

无关闭按钮IE

window.open("aa.htm", "meizz", "fullscreen=7");

统一编码/解码

alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))

encodeURIComponent对":"、"/"、";" 和 "?"也编码

表格行指示

tr onmouseover="this.bgColor='#f0f0f0'" onmouseout="this.bgColor='#ffffff'"

//各种尺寸

s += "\r\n网页可见区域宽:"+ document.body.clientWidth;

s += "\r\n网页可见区域高:"+ document.body.clientHeight;

s += "\r\n网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)";

s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";

s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;

s += "\r\n网页正文全文高:"+ document.body.scrollHeight;

s += "\r\n网页被卷去的高:"+ document.body.scrollTop;

s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;

s += "\r\n网页正文部分上:"+ window.screenTop;

s += "\r\n网页正文部分左:"+ window.screenLeft;

s += "\r\n屏幕分辨率的高:"+ window.screen.height;

s += "\r\n屏幕分辨率的宽:"+ window.screen.width;

s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;

s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;

//过滤数字

input type=text onkeypress="return event.keyCode=48event.keyCode=57||(this.value.indexOf('.')0?event.keyCode==46:false)" onpaste="return !clipboardData.getData('text').match(/\D/)" ondragenter="return false"

//特殊用途

input type=button value=导入收藏夹 onclick="window.external.ImportExportFavorites(true,'');"

input type=button value=导出收藏夹 onclick="window.external.ImportExportFavorites(false,'');"

input type=button value=整理收藏夹 onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)"

input type=button value=语言设置 onclick="window.external.ShowBrowserUI('LanguageDialog', null)"

input type=button value=加入收藏夹 onclick="window.external.AddFavorite('', 'google')"

input type=button value=加入到频道 onclick="window.external.addChannel('')"

input type=button value=加入到频道 onclick="window.external.showBrowserUI('PrivacySettings',null)"

//不缓存

META HTTP-EQUIV="pragma" CONTENT="no-cache"

META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"

META HTTP-EQUIV="expires" CONTENT="0"

//正则匹配

匹配中文字符的正则表达式: [\u4e00-\u9fa5]

匹配双字节字符(包括汉字在内):[^\x00-\xff]

匹配空行的正则表达式:\n[\s| ]*\r

匹配HTML标记的正则表达式:/(.*).*\/\1|(.*) \//

匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim函数)

匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%=]*)?

以下是例子:

利用正则表达式限制网页表单里的文本框输入内容:

用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"

1.用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"

2.用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

3.用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

关于Echarts及echarts-for-react的内存泄漏问题

最近接到大屏需求全部都是图表展示,在测试的时候有两次白屏了,这让我担心会不会是内存泄漏导致的毕竟Echarts真的有这个问题哈。

ECharts在每次 setOption 后都需要清理变量,在ECharts中是有API手动清理变量的,分别是 clear() 和 dispose() ,区别是前者只需插入参数,ECharts就会重绘图表;而后者则是直接将ECharts对象进行清理,需要重新构建ECharts对象。另外,针对IE,也有专门的回收内存函数 CollectGarbage ,每次浏览器最小化的时候,浏览器都会调用该函数,清理内存。

chart.dispose() 配合 echarts.init() ,然后再 setOption() 。或者调用其 clear() 方法。

具体可以参见

关于这个插件,我看了一下它的解决办法,它在 componentDidUpdate 和 componentWillUnmount 两个生命周期内都进行了处理:

从网页上导出的电子表格存在哪里?

Code highlighting produced by Actipro CodeHighlighter (freeware);%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head runat="server"

title导出为excel/title

script type="text/javascript"

function printToExcel(html) {

  try{

  var ExApp = new ActiveXObject("Excel.Application") //创建应该对象

  var ExWBk = ExApp.workbooks.add() //新建一个Excel工作簿

  var ExWSh = ExWBk.worksheets(1) //指定要写入内容的工作表为活动工作表

  ExApp.DisplayAlerts = false

  ExApp.visible = true

  }catch(e){

  alert("您所设定的安全级别太高,或者您的电脑没有安装Microsoft Excel软件!")

  return false

  }

  window.clipboardData.setData("Text", html); 

  ExWBk.worksheets(1).Paste;

  ExWBk.worksheets(1).Columns.AutoFit;

  ExWBk.worksheets(1).Rows.AutoFit;

}

function printToWord(html)

{

var word = new ActiveXObject("Word.Application");

// var doc = word .documents.open("c:\test.doc"); //此处为打开已有的模版

var doc = word .Documents.Add("",0,1);//不打开模版直接加入内容

var Range=doc.Range();

var sel = document.body.createTextRange();

sel.moveToElementText(html);//此处form是页面form的id

sel.select();

sel.execCommand("Copy");

Range.Paste();

word .Application.Visible = true;

word.Application.Selection.InlineShapes.AddPicture("c:\\m20.gif");

doc .saveAs("c:\\ba.doc"); //存放到指定的位置注意路径一定要是“\\”不然会报错

}

/script

/head

body

!-- 以下为数据区 --

div id="dataArea"

p style="color: Red; font-size: 20px;"

2009年猪流感统计表/p

table border="1" cellpadding="0" style="border-collapse: collapse;"

tbody

tr

td

b编号/b/td

td

b用户名/b/td

/tr

tr

td

b编号/b/td

td

b用户名/b/td

/tr

/tbody

/table

br /

input id="btExcel" type="button" onclick="printToExcel(dataArea.innerHTML);" value="导出为Excel" /

input id="Button1" type="button" onclick="printToWord(dataArea);" value="导出为Word" /

/div

/body

/html

1.创建一个新Excel表格 var XLObj = new ActiveXObject("Excel.Application");

var xlBook = XLObj.Workbooks.Add; //新增工作簿

var ExcelSheet = xlBook.Worksheets(1); //创建工作表 2.保存表格

ExcelSheet.SaveAs("C:\\TEST.XLS"); 3.使 Excel 通过 Application 对象可见

ExcelSheet.Application.Visible = true; 4.打印

xlBook.PrintOut;

或者:

ExcelSheet.PrintOut; 5.关闭

xlBook.Close(savechanges=false);

或者:

ExcelSheet.Close(savechanges=false); 6.结束进程

ExcelSheet.Application.Quit();

或者:

XLObj.Quit();

XLObj=null;function endXlsObj(){

oXL.UserControl = true;

oXL=null;

oWB=null;

activeSheet=null;

//结束excel进程,退出完成

idTmr = window.setInterval("Cleanup();",1);

}

function Cleanup() {

window.clearInterval(idTmr);

CollectGarbage();

} 7.页面设置 ExcelSheet.ActiveSheet.PageSetup.Orientation = 2;

ExcelSheet.ActiveSheet.PageSetup.LeftMargin= 2/0.035; //页边距 左2厘米

ExcelSheet.ActiveSheet.PageSetup.RightMargin = 3/0.035; //页边距 右3厘米,

ExcelSheet.ActiveSheet.PageSetup.TopMargin = 4/0.035; //页边距 上4厘米,

ExcelSheet.ActiveSheet.PageSetup.BottomMargin = 5/0.035; //页边距 下5厘米

ExcelSheet.ActiveSheet.PageSetup.HeaderMargin = 1/0.035; //页边距 页眉1厘米

ExcelSheet.ActiveSheet.PageSetup.FooterMargin = 2/0.035; //页边距 页脚2厘米

ExcelSheet.ActiveSheet.PageSetup.CenterHeader = "页眉中部内容";

ExcelSheet.ActiveSheet.PageSetup.LeftHeader = "页眉左部内容";

ExcelSheet.ActiveSheet.PageSetup.RightHeader = "页眉右部内容";

ExcelSheet.ActiveSheet.PageSetup.LeftFooter = "页脚左部内容";

ExcelSheet.ActiveSheet.PageSetup.RightFooter = "页脚右部内容"; ExcelSheet.ActiveSheet.PageSetup.CenterHeader = "\"宋体,加粗\"18长天公司" + date1 + "至" + date2 + "(施工图)项目进度检查表";

ExcelSheet.ActiveSheet.PageSetup.RightHeader = "D";

ExcelSheet.ActiveSheet.PageSetup.PrintGridlines = true;

ExcelSheet.ActiveSheet.PageSetup.PrintTitleRows = "$1:$1";

ExcelSheet.ActiveSheet.PageSetup.Zoom = 75; 8.对单元格操作,带*部分对于行,列,区域都有相应属性

ExcelSheet.ActiveSheet.Cells(row,col).Value = "内容"; //设置单元格内容

ExcelSheet.ActiveSheet.Cells(row,col).Borders.Weight = 1; //设置单元格边框*()

ExcelSheet.ActiveSheet.Cells(row,col).Interior.ColorIndex = 1; //设置单元格底色*(1-黑色,

2-白色,3-红色,4-绿色,5-蓝色,6-黄色,7-粉红色,8-天蓝色,9-酱土色..可以多做尝试)

ExcelSheet.ActiveSheet.Cells(row,col).Interior.Pattern = 1; //设置单元格背景样式*(1-无,

2-细网格,3-粗网格,4-斑点,5-横线,6-竖线..可以多做尝试)

ExcelSheet.ActiveSheet.Cells(row,col).Font.ColorIndex = 1; //设置字体颜色*(与上相同)

ExcelSheet.ActiveSheet.Cells(row,col).Font.Size = 10; //设置为10号字*

ExcelSheet.ActiveSheet.Cells(row,col).Font.Name = "黑体"; //设置为黑体*

ExcelSheet.ActiveSheet.Cells(row,col).Font.Italic = true; //设置为斜体*

ExcelSheet.ActiveSheet.Cells(row,col).Font.Bold = true; //设置为粗体*

ExcelSheet.ActiveSheet.Cells(row,col).ClearContents; //清除内容*

ExcelSheet.ActiveSheet.Cells(row,col).WrapText=true; //设置为自动换行*

ExcelSheet.ActiveSheet.Cells(row,col).HorizontalAlignment = 3; //水平对齐方式枚举* (1-常规,

2-靠左,3-居中,4-靠右,5-填充 6-两端对齐,7-跨列居中,8-分散对齐)

ExcelSheet.ActiveSheet.Cells(row,col).VerticalAlignment = 2; //垂直对齐方式枚举*(1-靠上,

2-居中,3-靠下,4-两端对齐,5-分散对齐)

//行,列有相应操作:

ExcelSheet.ActiveSheet.Rows(row).

ExcelSheet.ActiveSheet.Columns(col).

ExcelSheet.ActiveSheet.Rows(startrow+":"+endrow). //如Rows("1:5")即1到5行

ExcelSheet.ActiveSheet.Columns(startcol+":"+endcol). //如Columns("1:5")即1到5列

//区域有相应操作:

XLObj.Range(startcell+":"+endcell).Select;

//如Range("A2:H8")即A列第2格至H列第8格的整个区域

XLObj.Selection.

//合并单元格

XLObj.Range(startcell+":"+endcell).MergeCells = true;

//如Range("A2:H8")即将A列第2格至H列第8格的整个区域合并为一个单元格

或者:

XLObj.Range("A2",XLObj.Cells(8, 8)).MergeCells = true; 9.设置行高与列宽

ExcelSheet.ActiveSheet.Columns(startcol+":"+endcol).ColumnWidth = 22;

//设置从firstcol到stopcol列的宽度为22

ExcelSheet.ActiveSheet.Rows(startrow+":"+endrow).RowHeight = 22;

//设置从firstrow到stoprow行的宽度为22

js 能读出exc中的图片吗

只要网页能显示图片,就能导出到EXCEL

script

var idTmr = "";

function copy(tabid){

var oControlRange = document.body.createControlRange();

oControlRange.add(tabid,0);

oControlRange.select();

document.execCommand("Copy");

}

function toExcel(tabid){

copy(tabid);

try{

var xls = new ActiveXObject( "Excel.Application" );

}catch(e){

alert( "Excel没有安装或浏览器设置不正确.请启用所有Active控件和插件");

return false;

}

xls.visible = true;

var xlBook = xls.Workbooks.Add;

var xlsheet = xlBook.Worksheets(1);

xlBook.Worksheets(1).Activate;

for(var i=0;itabid.rows(0).cells.length;i++){

xlsheet.Columns(i+1).ColumnWidth=15;

}

xlsheet.Paste;

xls=null;

idTmr = window.setInterval("Cleanup();",1);

}

function Cleanup() {

window.clearInterval(idTmr);

CollectGarbage();

}

/script

input type="button" value="导入excel" onclick="toExcel(t1)" !--把table的ID传过去就好了--

table id="t1"

你的table

/table

//在IE浏览器里工具-》internet选项-》安全-》自定义级别-》把你禁用的都打开

js生成Excel 怎么设置 文件名称

面代码保存.js文件使用候调用extGridToExcel() var idTmr = ""; function Cleanup() { window.clearInterval(idTmr); CollectGarbage(); } extGridToExcel = function(grid){ try

(责任编辑:IT教学网)

更多

相关CMS技巧文章

推荐CMS技巧文章