惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
L
LangChain Blog
博客园_首页
Recent Announcements
Recent Announcements
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
博客园 - 叶小钗
博客园 - 【当耐特】
The Cloudflare Blog
J
Java Code Geeks
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans

博客园 - hone

管理 java学习 服务器相关 总统和亿万富翁经典语录(转载) 最近学习计划 VC控制Excel 真乱(转自csdn) 沟通(网上搜集) 工作 无题 将文档发送到打印机(From MSN) 经典68个故事 Manually Invalidating All Stale Sessions java的zip压缩(转自Jeet) 图形相关 在Oracle9i中计算时间差 六度分隔 经典故事 新年竟然第一篇?!
js学习笔记
hone · 2007-01-23 · via 博客园 - hone

1.匿名函数

2.定义函数之后就可以立即使用它

1function(x,y,z) return (x+y+z) } ) (123);
2

可以在括号中编写函数表达式,然后传递给参数,对参数进行运算。
3.将函数作为参数传递,并应用该函数:

1var passFunAndApply = function (fn,x,y,z) return fn(x,y,z); };
2
3var sum = function(x,y,z) {
4  return x+y+z;
5}
;
6
7alert( passFunAndApply(sum,3,4,5) ); // 12

执行最后一个 alert 语句输出了一个大小为 12 的值。

JavaScript 中的函数式风格作一快速总结:

  • 函数并不总是需要名称。
  • 函数可以像其他值一样分配给变量。
  • 函数表达式可以编写并放在括号中,留待以后应用。
  • 函数可以作为参数传递给其他函数。

4.在回调中调用一组函数

1window.setTimeout(function(){alert(‘First!’);alert(‘Second!’);}5000);

5.调用系列函数的更好的方式

 1 Function.prototype.sequence=function(g) {
 2   var f=this;
 3   return function() {
 4     f();g();
 5   }
 6 };
 7 function alertFrst() { alert(‘First!’); }
 8 function alertSec() { alert(‘Second!’); }
 9 setTimeout( alertFrst.sequence(alertSec), 5000);
10 

6.打印html

// creates an invisible iframe, puts the original source code inside and prints it
PrintSource = function(sender)
{
    
var td        = sender.parentNode;
    
var code    = td.processedCode;
    
var iframe    = document.createElement('IFRAME');
    
var doc        = null;
    
var wnd        = 

    
// this hides the iframe
    iframe.style.cssText = 'position:absolute; width:0px; height:0px; left:-5px; top:-5px;';
    
    td.appendChild(iframe);
    
    doc 
= iframe.contentWindow.document;
    code 
= code.replace(/</g, '&lt;');
    
    doc.open();
    doc.write('
<pre>+ code + '</pre>');
    doc.close();
    
    iframe.contentWindow.focus();
    iframe.contentWindow.print();
    
    td.removeChild(iframe);
}

//自带的打印预览 

WebBrowser.ExecWB(
1,1) 打开  
Web.ExecWB(
2,1) 关闭现在所有的IE窗口,并打开一个新窗口  
Web.ExecWB(
4,1) 保存网页  
Web.ExecWB(
6,1) 打印  
Web.ExecWB(
7,1) 打印预览  
Web.ExecWB(
8,1) 打印页面设置  
Web.ExecWB(
10,1) 查看页面属性  
Web.ExecWB(
15,1) 好像是撤销,有待确认  
Web.ExecWB(
17,1) 全选  
Web.ExecWB(
22,1) 刷新  
Web.ExecWB(
45,1) 关闭窗体无提示  
<style media=print>  
.Noprint{display:none;}
<!--用本样式在打印时隐藏非打印项目-->  
.PageNext{page
-break-after: always;}<!--控制分页-->  
</style>  
<object  id="WebBrowser"  width=0  height=0  classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">     
</object>     
  
<center class="Noprint" > 
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>  
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>  
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>  
</p>  
<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>  
</center> 
//去掉打印时的页眉页脚 

 
<script  language="JavaScript">   
var HKEY_Root,HKEY_Path,HKEY_Key; 
HKEY_Root
="HKEY_CURRENT_USER"
HKEY_Path
="\Software\Microsoft\Internet Explorer\PageSetup\"
//设置网页打印的页眉页脚为空 
function PageSetup_Null() 

 
try 
 { 
         
var Wsh=new ActiveXObject("WScript.Shell"); 
  HKEY_Key
="header"
  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,""); 
  HKEY_Key
="footer"
  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,""); 
 } 
 
catch(e){} 

//设置网页打印的页眉页脚为默认值 
function  PageSetup_Default() 
{   
 
try 
 { 
  
var Wsh=new ActiveXObject("WScript.Shell"); 
  HKEY_Key
="header"
  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P"); 
  HKEY_Key
="footer"
  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"&u&b&d"); 
 } 
 
catch(e){} 

</script> 
<input type="button" value="清空页码" onclick=PageSetup_Null()> 
<input type="button" value="恢复页码" onclick=PageSetup_Default()>