预览模式: 普通 | 列表

使用JQuery使Div居中

Div居中是一个比较常见的需求。下面介绍一种使用JQuery使Div居中的方法
先假设有这样一个Div,<div id="d">test</div>
首先是要把需要居中的Div进行绝对定位,如:
<style type="text/css">
#d {
position: absolute;
width: 500;
height: 300;
border: 1px solid red;
}
</style>
有了这样的样式定义之后就是使其居中的js代码了。

JavaScript代码
  1. var obj = $("#d");//获得相应的Div对象    
  2. var x = ($(window).width()-500)/2;//使用$(window).width()获得显示器的宽,并算出对应的Div离左边的距离    
  3. var y = ($(window).height()-300)/2;//使用$(window).height()获得显示器的高,并算出相应的Div离上边的距离    
  4. obj.css("top",y).css("left",x);  

上面这段代码可以在页面一加载完就执行。

改进后的代码:

JavaScript代码
  1. $(document).ready(function(){  
  2.     middle();  
  3. });  
  4. $(window).resize(function(){  
  5.     middle();  
  6. });  
  7. function middle(){  
  8.     var obj = $("#mainbg");//获得相应的Div对象    
  9.     var x = ($(window).width()-500)/2;//使用$(window).width()获得显示器的宽,并算出对应的Div离左边的距离    
  10.     var y = ($(window).height()-300)/2;//使用$(window).height()获得显示器的高,并算出相应的Div离上边的距离    
  11.     obj.css("top",y).css("left",x);   
  12. }  

上面的代码实现窗口大小变化后始终居中。

Tags: javascript jquery

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2077

css背景颜色渐变

 垂直方向:

CSS代码
  1. filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900',gradientType='0');  
  2.   
  3. background: -moz-linear-gradient(top#FF0000#F9F900);  
  4.   
  5. background: -o-linear-gradient(top,#FF0000#F9F900);  
  6.   
  7. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FF0000), to(#F9F900));  

水平方向:

CSS代码
  1. filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900',gradientType='1');  
  2.   
  3. background: -moz-linear-gradient(left#FF0000#F9F900);  
  4.   
  5. background: -o-linear-gradient(left,#FF0000#F9F900);  
  6.   
  7. background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#FF0000), to(#F9F900));  

Tags: css

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2122

jQuery禁止鼠标右键

 jQuery屏蔽鼠标右键:
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
--------------------------------------------------------------------------------------------------
JS屏蔽鼠标右键:
<script language="JavaScript">
document.oncontextmenu=new Function("event.returnValue=false;");
document.onselectstart=new Function("event.returnValue=false;");
</script>
--------------------------------------------------------------------------------------------------
jquery禁止右键弹出的突破方法:
如: $(document).bind("contextmenu", function() { return false; }); //这段JS代码将禁止右键弹出
突破方法:
地址栏中输入:javascript:alert($(document).unbind("contextmenu",""));

Tags: javascript jquery

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2665

JavaScript获取当前根目录

主要用到Location 对象,包含有关当前 URL 的信息,是 Window 对象的一个部分,可通过 window.location 属性来访问。

方法一 (window.document.location.href/window.document.location.pathname) 

JavaScript代码
  1. function getRootPath_web() {  
  2.             //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp  
  3.             var curWwwPath = window.document.location.href;  
  4.             //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp  
  5.             var pathName = window.document.location.pathname;  
  6.             var pos = curWwwPath.indexOf(pathName);  
  7.             //获取主机地址,如: http://localhost:8083  
  8.             var localhostPaht = curWwwPath.substring(0, pos);  
  9.             //获取带"/"的项目名,如:/uimcardprj  
  10.             var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);  
  11.             return (localhostPaht + projectName);  
  12.         }  

方法二(window.location.pathname/window.location.protocol/window.location.host)

JavaScript代码
  1. function getRootPath_dc() {  
  2.             var pathName = window.location.pathname.substring(1);  
  3.             var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));  
  4.             if (webName == "") {  
  5.                 return window.location.protocol + '//' + window.location.host;  
  6.             }  
  7.             else {  
  8.                 return window.location.protocol + '//' + window.location.host + '/' + webName;  
  9.             }  
  10.         }  

注:

查看更多...

Tags: javascript

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 1673

在内容页加入:

PHP:header("Content-type: text/html; charset=gb2312");

ASP:response.Charset="GB2312"

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 1832

asp之字符串操作函数

 asp之字符串函数示例

用字符串函数对字符串进行截头去尾、大小写替换等操作。

函数 语法 功能
Len Len(string|varname) 返回字符串内字符的数目,或是存储一变量所需的字节数。
Trim Trim(string) 将字符串前后的空格去掉
Ltrim Ltrim(string) 将字符串前面的空格去掉
Rtrim Rtrim(string) 将字符串后面的空格去掉
Mid Mid(string,start,length) 从string字符串的start字符开始取得length长度的字符串,如果省略第三个参数表示从start字符开始到字符串结尾的字符串
Left Left(string,length) 从string字符串的左边取得length长度的字符串
Right Right(string,length) 从string字符串的右边取得length长度的字符串
LCase LCase(string) 将string字符串里的所有大写字母转化为小写字母
UCase UCase(string) 将string字符串里的所有大写字母转化为大写字母
StrComp StrComp(string1,string2[,compare]) 返回string1字符串与string2字符串的比较结果,如果两个字符串相同,则返回0,如果小于则返回-1,如果大于则返回1
InStr InStr(string1,string2[, compare]) 返回string1字符串在string2字符串中第一次出现的位置
Split Split(string1,delimiter[, count[, start]])

将字符串根据delimiter拆分成一维数组,其中delimiter用于标识子字符串界限。如果省略,使用空格("")作为分隔符。
count 返回的子字符串数目,-1 指示返回所有子字符串。
start为 1 执行文本比较;如果为 0 或者省略执行二进制比较。

Replace Replace(e­xpression, find, replacewith[, compare[, count[, start]]]) 返回字符串,其中指定数目的某子字符串(find)被替换为另一个子字符串(replacewith)。

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 1931

ACCESS库可以这样书写:

ASP/Visual Basic代码
  1. set rs = server.createobject("adodb.recordset")    
  2. sql = "select * from table   
  3. rs.addnew   
  4. rs("title") = "title"   
  5. rs("content") = "content"   
  6. rs.update   
  7. newid = rs("id")    
  8. rs.close    

SQLSERVER用上面的方法不行,必须在Update后多加一句,rs.movelast.

ASP/Visual Basic代码
  1. set rs = server.createobject("adodb.recordset")    
  2. sql = "select * from table   
  3. rs.addnew   
  4. rs("title") = "title"   
  5. rs("content") = "content"   
  6. rs.update   
  7. rs.movelast   
  8. newid = rs("id")    
  9. rs.close    

SqlServer中的自增的ID的最后的值:

Select SCOPE_IDENTITY() --返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值。
Select @@IDENTITY    --返回插入到当前会话中任何作用域内的最后一个 IDENTITY 列值
Select IDENT_CURRENT('TbName')--不受作用域和会话的限制,而受限于指定的表。
IDENT_CURRENT 返回为任何会话和作用域中的特定表所生成的值。

查看更多...

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3073

 

PHP代码
  1. //if(!preg_match(" /^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_]+$/ ",$str)) //GB2312汉字字母数字下划线正则表达式   
  2.     if(!preg_match(" /^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/ ",$str))   //UTF-8汉字字母数字下划线正则表达式  
  3.     {     
  4.         echo "<font color=red>您输入的[".$str."]含有违法字符</font>";     
  5.     }  
  6.     else   
  7.     {  
  8.         echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>";     
  9.     }  

 

Tags: php

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2729

 广告位

↑返回顶部↑