常用的WEB代码

1.日期减去天数等于第二个日期

function cc(dd,dadd) 

    //可以加上错误处理 
    var d = new Date(dd.replace("-","/")) 
    d.setDate(d.getDate()+dadd) 
    alert(d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日") 
}  


2.TEXTAREA自适应文字行数的多少 

IE 5.5+ 可以用 overflow-y:visible 
<textarea rows=1 name=s1 cols=27 style="overflow-y:visible"> </textarea> 


3.普通弹出窗口

<SCRIPT LANGUAGE="javascript"> 
<!-- 
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no,status=no') 
//写成一行 
--> 
</SCRIPT> 
参数解释: 
<SCRIPT LANGUAGE="javascript"> js脚本开始; 
window.open 弹出新窗口的命令; 
'page.html' 弹出窗口的文件名; 
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替; 
height=100 窗口高度; 
width=400 窗口宽度; 
top=0 窗口距离屏幕上方的象素值; 
left=0 窗口距离屏幕左侧的象素值; 
toolbar=no 是否显示工具栏,yes为显示; 
menubar,scrollbars 表示菜单栏和滚动栏。 
resizable=no 是否允许改变窗口大小,yes为允许; 
location=no 是否显示地址栏,yes为允许; 
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许; 
</SCRIPT> js脚本结束  


4.showModelessDialog()和showModalDialog()使用

    showModalDialog() (IE 4+ 支持)
 showModelessDialog() (IE 5+ 支持)

    window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框,由于是对话框,因此它并没有一般用window.open()打开的窗口的所有属性。

    window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。 

    当我们用showModelessDialog()打开窗口时,不必用window.close()去关闭它,当以非模态方式[IE5]打开时, 打开对话框的窗口仍可以进行其他的操作,即对话框不总是最上面的焦点,当打开它的窗口URL改变时,它自动关闭。而模态[IE4]方式的对话框始终有焦点(焦点不可移走,直到它关闭)。模态对话框和打开它的窗口相联系,因此我们打开另外的窗口时,他们的链接关系依然保存,并且隐藏在活动窗口的下面。

使用方法如下:
    vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
    vReturnValue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])

参数说明:
    sURL
   必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
    vArguments
   可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
    sFeatures
   可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
    dialogHeight 对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
  dialogWidth: 对话框宽度。
  dialogLeft: 距离桌面左的距离。
  dialogTop: 离桌面上的距离。
  center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
  help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
  resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
  status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
    scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。

还有几个属性是用在HTA中的,在一般的网页中一般不使用。
    dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
    edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
    unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。

传入参数:
    要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,如最常用的window

注:模式和非模式区别在于被打开后是否保持"焦点"。

例子:

a.htm

<script language="javascript"> 
var s=showModalDialog("b.html",window,"dialogTop:200px;dialogLeft:300px");
</script>
<input type="button" value="s" onclick="alert(s);">

b.htm

<input type="button" value="关闭" onclick="window.returnValue='aaa';window.close();">



5.IE 控制命令

打开,另存为,属性,打印"等14个JS代码

■打开■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开> 
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■另存为■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■属性■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■打印■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■页面设置■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置><OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■刷新■ 
<input type=button value=刷新 name=refresh onclick="window.location.reload()"> 
■导入收藏■ 
<input type="button" name="Button" value="导入收藏夹" onClick=window.external.ImportExportFavorites(true,);> 
■导出收藏■ 
<input type="button" name="Button3" value="导出收藏夹" onClick=window.external.ImportExportFavorites(false,);> 
■加入收藏■ 
<INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹> 
■整理收藏夹■ 
<INPUT name=Submit2 onclick="window.external.ShowBrowserUI(OrganizeFavorites, null)" type=button value=整理收藏夹> 
■查看原文件■ 
<INPUT name=Button onclick=window.location = "view-source:" + window.location.href type=button value=查看源文件> 
■语言设置■ 
<INPUT name=Button onclick="window.external.ShowBrowserUI(LanguageDialog, null)" type=button value=语言设置> 
■前进■ 
<INPUT name=Submit onclick=history.go(1) type=submit value=前进> 
■后退■ 
<INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退>


6.meta 的作用

  name 属性 

  1、<meta name="Generator" contect="">用以说明生成工具(如Microsoft FrontPage 4.0)等; 

  2、<meta name="KEYWords" contect="">向搜索引擎说明你的网页的关键词; 

  3、<meta name="DEscription" contect="">告诉搜索引擎你的站点的主要内容; 

  4、<meta name="Author" contect="你的姓名">告诉搜索引擎你的站点的制作的作者; 

  5、<meta name="Robots" contect= "all|none|index|noindex|follow|nofollow"> 

  其中的属性说明如下: 

  设定为all:文件将被检索,且页面上的链接可以被查询; 

  设定为none:文件将不被检索,且页面上的链接不可以被查询; 

  设定为index:文件将被检索; 

  设定为follow:页面上的链接可以被查询; 

  设定为noindex:文件将不被检索,但页面上的链接可以被查询; 

  设定为nofollow:文件将不被检索,页面上的链接可以被查询。 

  http-equiv属性 

  1、<meta http-equiv="Content-Type" contect="text/html";charset=gb_2312-80"> 

和 <meta http-equiv="Content-Language" contect="zh-CN">用以说明主页制作所使用的文字以及语言; 

  又如英文是ISO-8859-1字符集,还有BIG5、utf-8、shift-Jis、Euc、Koi8-2等字符集; 

  2、<meta http-equiv="Refresh" contect="n;url=http://yourlink">定时让网页在指定的时间n内,跳转到页面http://yourlink; 

  3、<meta http-equiv="Expires" contect="Mon,12 May 2001 00:20:00 GMT">可以用于设定网页的到期时间,一旦过期则必须到服务器上重新调用。需要注意的是必须使用GMT时间格式; 

  4、<meta http-equiv="Pragma" contect="no-cache">是用于设定禁止浏览器从本地机的缓存中调阅页面内容,设定后一旦离开网页就无法从Cache中再调出; 

  5、<meta http-equiv="set-cookie" contect="Mon,12 May 2001 00:20:00 GMT">cookie设定,如果网页过期,存盘的cookie将被删除。需要注意的也是必须使用GMT时间格式; 

  6、<meta http-equiv="Pics-label" contect="">网页等级评定,在IE的internet选项中有一项内容设置,可以防止浏览一些受限制的网站,而网站的限制级别就是通过meta属性来设置的; 

  7、<meta http-equiv="windows-Target" contect="_top">强制页面在当前窗口中以独立页面显示,可以防止自己的网页被别人当作一个frame页调用; 

  8、<meta http-equiv="Page-Enter" contect="revealTrans(duration=10,transtion= 50)">和<meta http-equiv="Page-Exit" contect="revealTrans(duration=20,transtion=6)">设定进入和离开页面时的特殊效果,这个功能即FrontPage中的“格式/网页过渡”,不过所加的页面不能够是一个frame页面。 


评论: 0 | 引用: 1 | 查看次数: 3173
发表评论
昵 称:
密 码: 游客发言不需要密码.
验证码:
内 容:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭