现在的位置: 首页 > 综合 > 正文

收集的一些常用JS代码和CSS代码

2013年09月09日 ⁄ 综合 ⁄ 共 7367字 ⁄ 字号 评论关闭

<INPUT onclick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为 name=Button2>
<INPUT onclick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性 name=Button3>
<INPUT onclick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印 name=Button>
<INPUT onclick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置 name=Button4>
<INPUT onclick=window.location.reload() type=button value=刷新 name=refresh>
<INPUT onclick="window.external.ImportExportFavorites(true,'');" type=button value=导入收藏夹 name=Button5>
<INPUT onclick="window.external.ImportExportFavorites(false,'');" type=button value=导出收藏夹 name=Button32>
<INPUT onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹 name=Button22>
<INPUT onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)" type=button value=整理收藏夹 name=Submit2>
<INPUT onclick='window.location="view-source:" + window.location.href' type=button value=查看源文件 name=Button7>
<INPUT onclick="window.external.ShowBrowserUI('LanguageDialog', null)" type=button value=语言设置 name=Button6>
<INPUT onclick="document.execCommand('Cut')" type=button value=剪切>
<INPUT onclick="document.execCommand('Copy')" type=button value=拷贝>
<INPUT onclick="document.execCommand('Paste')" type=button value=粘贴>
<INPUT onclick="document.execCommand('Undo')" type=button value=撤消>
<INPUT onclick="document.execCommand('Delete')" type=button value=删除>
<INPUT onclick="document.execCommand('Bold')" type=button value=黑体>
<INPUT onclick="document.execCommand('Italic')" type=button value=斜体>
<INPUT onclick="document.execCommand('Underline')" type=button value=下划线>
<INPUT onclick="document.execCommand('stop')" type=button value=停止>
<INPUT onclick="document.execCommand('SaveAs')" type=button value=保存>
<INPUT onclick="document.execCommand('Saveas',false,'c://test.htm')" type=button value=另存为>
<INPUT onclick="document.execCommand('FontName',false,fn)" type=button value=字体>
<INPUT onclick="document.execCommand('FontSize',false,fs)" type=button value=字体大小>
<INPUT onclick="document.execCommand('refresh',false,0)" type=button value=刷新>
<INPUT onclick=window.location.reload() type=button value=刷新>
<INPUT onclick=history.go(1) type=button value=前进>
<INPUT onclick=history.go(-1) type=button value=后退>
<INPUT onclick=history.forward() type=button value=前进>
<INPUT onclick=history.back() type=button value=后退>
<INPUT onclick='window.external.ImportExportFavorites(true,"http://localhost";);' type=button value=导入收藏夹>
<INPUT onclick='window.external.ImportExportFavorites(false,"http://localhost";);' type=button value=导出收藏夹>
<INPUT onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)" type=button value=整理收藏夹>
<INPUT onclick="window.location = 'view-source:'+ window.location.href" type=button value=查看源文件>
<INPUT onclick="window.external.ShowBrowserUI('LanguageDialog', null)" type=button value=语言设置>
<INPUT onclick="window.external.AddFavorite('http://www.behar.cn', 十万个为什么)" type=button value=加入收藏夹>
<INPUT onclick="window.external.addChannel('http://www.behar.cn')" type=button value=加入到频道>
<INPUT onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('www.why100000.com')" type=button value=设成主页>

HTML关闭IE的图像工具栏
<META HTTP-EQUIV="imagetoolbar" CONTENT="no"> 来禁用,也可以通过对 IMG 标记元素设置属性  

解决select菜单边框无法设置的问题

<span style="border:1px solid green; position:absolute; overflow:hidden"><select style="margin:-2px">
<option>1111</option>
<option>11111111111111</option>
<option>111111111</option>
</select></span>

1.取消按钮按下时的虚线框
在input里添加属性值 hideFocus 或者 HideFocus=true
2.只读文本框内容
在input里添加属性值 readonly
3.防止退后清空的TEXT文档(可把style内容做做为类引用)
程序代码<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput>

4.ENTER键可以让光标移到下一个输入框
程序代码<input onkeydown="if(event.keyCode==13)event.keyCode=9" >

5.只能为中文(有闪动) 
 程序代码<input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">

6.只能为数字(有闪动)
程序代码<input onkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))">

7.只能为数字(无闪动)
程序代码<input style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false">

8.只能输入英文和数字(有闪动)
程序代码<input onkeyup="value=value.replace(/[/W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))">

9.屏蔽输入法
程序代码<input type="text" name="url" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9">
10. 只能输入 数字,小数点,减号(-) 字符(无闪动)
程序代码<input onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false">

11. 只能输入两位小数,三位小数(有闪动) 
程序代码<input maxlength=9 onkeyup="if(value.match(/^/d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(//./d*/./g,'.')" onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^/d{3}$/) || //./d{3}$/.test(value)) {event.returnValue=false}" id=text_kfxe name=text_kfxe>

盒尺寸
通常有下面四种书写方法:

property:value1; 表示所有边都是一个值value1;
property:value1 value2; 表示top和bottom的值是value1,right和left的值是value2
property:value1 value2 value3; 表示top的值是value1,right和left的值是value2,bottom的值是value3
property:value1 value2 value3 value4; 四个值依次表示top,right,bottom,left
方便的记忆方法是顺时针,上右下左。具体应用在margin和padding的例子如下:
margin:1em 0 2em 0.5em;

边框(border)
边框的属性如下:

border-width:1px;
border-style:solid;
border-color:#000;
可以缩写为一句:border:1px solid #000;

语法是border:width style color;

背景(Backgrounds)
背景的属性如下:

background-color:#f00;
background-image:url(background.gif);
background-repeat:no-repeat;
background-attachment:fixed;
background-position:0 0;
可以缩写为一句:background:#f00 url(background.gif) no-repeat fixed 0 0;

语法是background:color image repeat attachment position;

你可以省略其中一个或多个属性值,如果省略,该属性值将用浏览器默认值,默认值为:

color: transparent
image: none
repeat: repeat
attachment: scroll
position: 0% 0%
字体(fonts)
字体的属性如下:

font-style:italic;
font-variant:small-caps;
font-weight:bold;
font-size:1em;
line-height:140%;
font-family:"Lucida Grande",sans-serif;
可以缩写为一句:font:italic small-caps bold 1em/140% "Lucida Grande",sans-serif;

注意,如果你缩写字体定义,至少要定义font-size和font-family两个值。

列表(lists)
取消默认的圆点和序号可以这样写list-style:none;,

list的属性如下:

list-style-type:square;
list-style-position:inside;
list-style-image:url(image.gif);
可以缩写为一句:list-style:square inside url(image.gif);]]>

一般用CSS设定字体属性是这样做的:

font-weight:bold;
font-style:italic;
font-varient:small-caps;
font-size:1em;
line-height:1.5em;
font-family:verdana,sans-serif;

但也可以把它们全部写到一行上去:

font: bold italic small-caps 1em/1.5em verdana,sans-serif;

真不错!只有一点要提醒的:这种简写方法只有在同时指定font-size和font-family属性时才起作用。而且,如果你没有设定font-weight, font-style, 以及 font-varient ,他们会使用缺省值,这点要记上。

如果想做个固定宽度的网页并且想让网页水平居中的话,通常是这样:

#content { width: 700px; margin: 0 auto }

你会使用 <div id="content"> 来围上所有元素。这很简单,但不够好,IE6之前版本会显示不出这种效果。改CSS如下:

body { text-align: center } #content { text-align: left; width: 700px; margin: 0 auto }

这会把网页内容都居中,所以在Content中又加入了
text-align: left 。

垂直对齐用表格可以很方便地实现,设定表格单元 vertical-align: middle 就可以了。但对CSS来说这没用。如果你想设定一个导航条是2em高,而想让导航文字垂直居中的话,设定这个属性是没用的。

CSS方法是什么呢?对了,把这些文字的行高设为 2em:line-height: 2em ,这就可以了。

9. CSS在容器内定位

CSS的一个好处是可以把一个元素任意定位,在一个容器内也可以。比如对这个容器:

#container { position: relative }

这样容器内所有的元素都会相对定位,可以这样用:
<div id="container"><div id="navigation">...</div></div>
如果想定位到距左30点,距上5点,可以这样:

#navigation { position: absolute; left: 30px; top: 5px }

当然,你还可以这样:
margin: 5px 0 0 30px
注意4个数字的顺序是:上、右、下、左。当然,有时候定位的方法而不是边距的方法更好些。

10. 直通到屏幕底部的背景色

在垂直方向是进行控制是CSS所不能的。如果你想让导航栏和内容栏一样直通到页面底部,用表格是很方便的,但如果只用这样的CSS:

#navigation { background: blue; width: 150px }

较短的导航条是不会直通到底部的,半路内容结束时它就结束了。该怎么办呢?

不幸的是,只能采用欺骗的手段了,给这较短的一栏加上个背景图,宽度和栏宽一样,并让它的颜色和设定的背景色一样。

body { background: url(blue-image.gif) 0 0 repeat-y }

此时不能用em做单位,因为那样的话,一旦读者改变了字体大小,这个花招就会露馅,只能使用px

抱歉!评论已关闭.