常用Js、Css

记录一些常用的JS CSS,方便以后用到时查找

1.自动跳转页面

<meta http-equiv="refresh" content="0;url=http://www.lanrentuku.com">

2.网页中如何让整段文字左右对齐

<div style="font-size:12px;width:300;text-align:justify; text-justify:inter-ideograph"> 

3.iframe 自适应高度
设置了iframe的高度与宽度均为100% 可是在google chrome 下就正常 IE下高度不够 ???
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

修改这个试一下!!

4.屏蔽鼠标右键

oncontextmenu="window.event.returnvalue=false"

<table border oncontextmenu=return(false)><td>no</table> 可用于Table

5. 取消选取、防止复制<body onselectstart="return false"> 

6.不准粘贴  onpaste="return false" 

7.防止复制 oncopy="return false;" oncut="return false;" 

8. IE地址栏前换成自己的图标 <link rel="Shortcut Icon" href="favicon.ico">

9.可以在收藏夹中显示出你的图标<link rel="Bookmark" href="favicon.ico">

10.关闭输入法<input style="ime-mode:disabled">

11. 网页将不能被另存为<noscript><iframe src=*.html></iframe></noscript>

12.查看网页源代码

<input type=button value=查看网页源代码
onclick="window.location = 'view-source:'+ 'http://oschina.net/'">

13.通过asp的手段来检查来访者是否用了代理

<% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then
response.write "<font color=#FF0000>您通过了代理服务器,"& _
"真实的IP为"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
end if
%>

14. 防止被人frame

<script LANGUAGE=javascript><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>

15.永远都会带着框架

<script language="javascript"><!--
if (window == top)top.location.href = "frames.htm"; file://frames.htm为框架网页
// --></script>

16.设置页面不缓存

 response.setHeader("Pragma", "No-cache");
 response.setHeader("Cache-Control", "no-cache");

 response.setDateHeader("Expires", 0);

17.获取下拉列表值

<select size="1" id="selt">
<option value="1">Java网络编程学习资料</option>
<option value="2">Java深度历险</option>
<option value="3">Java完美编程</option>
</select>
<input type="button" value="提交" onclick="doSubmitForm()">

<script language=javascript type=text/javascript>    
function doSubmitForm(id)
{           
 var theele = document.getElementById('selt');         
 var content= theele.options[theele.selectedIndex].innerHTML;          
 alert(content);  
 theele.selectedIndex=theele.selectedIndex;
}

18.ul标签

ul是一个很常用的标签,但是因为它在Firefox和IE下的不同表现,让人觉得它是个很难以控制的标签。
ul在Firefox下有个padding值, 却没有margin值;而在IE下正好相反,ul有个margin值, 却没有padding值.
在Firefox下,ul的list-style默认是处于内容的外边缘的。当然可以通过css可以将list-style置为内容的内边缘。

通过权衡得到适合两个浏览器的设置:padding:0; margin:0; list-style:inside;。还可以将ul设置为padding:0; margin:0; list-style:none;,然后给li添加背景图片,也是很不错的选择。

19.去掉img间隔

a.插入代码:
img{display:block}
可以加在样式表的开头

b.定义容器里的字体大小为0。
插入代码:
div { 
width:110px; 
border:1px solid #000000; 
font-size:0 
}

c.定义图片img标签vertical-align:bottom,vertical-align:middle,vertical-align:top
插入代码:
img{vertical-align:bottom}
前三种方法已经可以完全解决了,其他方法还有把图片下边距设为负值和改写HTML标签的排列。 

你可能感兴趣的:(常用Js、Css)