使用JQuery使Div居中
作者:admin 日期:2015-05-29
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代码了。
- var obj = $("#d");//获得相应的Div对象
- var x = ($(window).width()-500)/2;//使用$(window).width()获得显示器的宽,并算出对应的Div离左边的距离
- var y = ($(window).height()-300)/2;//使用$(window).height()获得显示器的高,并算出相应的Div离上边的距离
- obj.css("top",y).css("left",x);
上面这段代码可以在页面一加载完就执行。
改进后的代码:
- $(document).ready(function(){
- middle();
- });
- $(window).resize(function(){
- middle();
- });
- function middle(){
- var obj = $("#mainbg");//获得相应的Div对象
- var x = ($(window).width()-500)/2;//使用$(window).width()获得显示器的宽,并算出对应的Div离左边的距离
- var y = ($(window).height()-300)/2;//使用$(window).height()获得显示器的高,并算出相应的Div离上边的距离
- obj.css("top",y).css("left",x);
- }
上面的代码实现窗口大小变化后始终居中。
css背景颜色渐变
作者:admin 日期:2015-05-29
垂直方向:
- filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900',gradientType='0');
- background: -moz-linear-gradient(top, #FF0000, #F9F900);
- background: -o-linear-gradient(top,#FF0000, #F9F900);
- background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FF0000), to(#F9F900));
水平方向:
- filter: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FF0000',endColorStr='#F9F900',gradientType='1');
- background: -moz-linear-gradient(left, #FF0000, #F9F900);
- background: -o-linear-gradient(left,#FF0000, #F9F900);
- background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#FF0000), to(#F9F900));
jQuery禁止鼠标右键
作者:admin 日期:2015-05-29
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",""));
JavaScript获取当前根目录
作者:admin 日期:2015-05-29
主要用到Location 对象,包含有关当前 URL 的信息,是 Window 对象的一个部分,可通过 window.location 属性来访问。
方法一 (window.document.location.href/window.document.location.pathname)
- function getRootPath_web() {
- //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
- var curWwwPath = window.document.location.href;
- //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
- var pathName = window.document.location.pathname;
- var pos = curWwwPath.indexOf(pathName);
- //获取主机地址,如: http://localhost:8083
- var localhostPaht = curWwwPath.substring(0, pos);
- //获取带"/"的项目名,如:/uimcardprj
- var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
- return (localhostPaht + projectName);
- }
方法二(window.location.pathname/window.location.protocol/window.location.host)
- function getRootPath_dc() {
- var pathName = window.location.pathname.substring(1);
- var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
- if (webName == "") {
- return window.location.protocol + '//' + window.location.host;
- }
- else {
- return window.location.protocol + '//' + window.location.host + '/' + webName;
- }
- }
注:
解决Jquery load()加载GB2312页面时出现乱码
作者:admin 日期:2015-05-25
asp之字符串操作函数
作者:admin 日期:2015-05-22
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用于标识子字符串界限。如果省略,使用空格("")作为分隔符。 |
Replace | Replace(expression, find, replacewith[, compare[, count[, start]]]) | 返回字符串,其中指定数目的某子字符串(find)被替换为另一个子字符串(replacewith)。 |
asp如何取得新插入记录的ID(ACCESS库和MSSQL方法不同)
作者:admin 日期:2015-05-20
ACCESS库可以这样书写:
- set rs = server.createobject("adodb.recordset")
- sql = "select * from table
- rs.addnew
- rs("title") = "title"
- rs("content") = "content"
- rs.update
- newid = rs("id")
- rs.close
SQLSERVER用上面的方法不行,必须在Update后多加一句,rs.movelast.
- set rs = server.createobject("adodb.recordset")
- sql = "select * from table
- rs.addnew
- rs("title") = "title"
- rs("content") = "content"
- rs.update
- rs.movelast
- newid = rs("id")
- rs.close
SqlServer中的自增的ID的最后的值:
Select SCOPE_IDENTITY() --返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值。
Select @@IDENTITY --返回插入到当前会话中任何作用域内的最后一个 IDENTITY 列值
Select IDENT_CURRENT('TbName')--不受作用域和会话的限制,而受限于指定的表。
IDENT_CURRENT 返回为任何会话和作用域中的特定表所生成的值。
php中用正则表达式匹配utf-8编码和GB2312编码的汉字
作者:admin 日期:2015-05-17
- //if(!preg_match(" /^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_]+$/ ",$str)) //GB2312汉字字母数字下划线正则表达式
- if(!preg_match(" /^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/ ",$str)) //UTF-8汉字字母数字下划线正则表达式
- {
- echo "<font color=red>您输入的[".$str."]含有违法字符</font>";
- }
- else
- {
- echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>";
- }
广告位