2011-01-17 00:14
特性探测很好,但有些情况下,特性很不好探测。 比如动态加载多个脚本时,在标准浏览器下,当脚本代码执行后,会立刻触发 onload
事件,中间不会穿插任何“广告”,这可用来获取脚本路径信息。但在 IE6/7/8
下,当脚本是从缓存中读取时,不穿插“广告”的规律不再可靠。要探测这种诡异差异时,纯特性探测很难有效构建。 上面这种情况下,不去纠结特性,而将特性归结到浏览器上,代码会美好很多: var isIE876 = !+'\v1'; var isIE76 = !'0'[0]; var isIE6 = isIE76 && !window.XMLHttpRequest; |
2010-12-20 09:47
测试代码如下: <button id="btn">确定</button> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script> var $loadScript = function(url, callback) { var script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState) { |
2010-12-16 10:44
测试代码如下: <style> .box{width:400px;} .main{height:200px; background:#a0b3d6;} .line{padding-top:1px; background-color:#a0b3d6; border:solid #D1D8E5; border-width:0 1px;} </style>
<div class="box"> <div id="topCurve"> <script> (function() { |
2010-12-11 13:26
if语句有些渐变的写法,但是不确定非定义情况下前面的变量是否全局,于是做了如下测试: (function() { var num = 1; if (txt = num.toString()) { alert(txt); } })(); alert(txt); 结果弹出连续两个1,表明,确实全局了,所以,等号前面的txt还是要var声明下的。 |
2010-11-22 15:35
在桌面上建了个空白txt文件,然后把如下代码拷进去:
rundll32.exe advpack.dll /DelNodeRunDLL32 %systemroot%\System32\dacui.dll
rundll32.exe advpack.dll /DelNodeRunDLL32 %systemroot%\Catroot\icatalog.mdb
regsvr32 /s comcat.dll
regsvr32 /s asctrls.ocx
regsvr32 /s oleaut32.dll
regsvr32 /s shdocvw.dll /I
regsvr32 /s shdocvw.dll
regsvr32 /s browseui.dll
regsvr32 /s browseui.dll /I
regsvr32 /s msrating.dll
reg |
2010-10-28 18:01
测试代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>letter-spacing负值在无空格时是否作用</title>
<link rel="stylesheet" href="http://www.zhangxinxu.com/study/css/zxx.lib.css" type="text/css" />
<style>
.test_box{width:46%; padding-top:10px; letter-spacing:-3px; font-family:Arial, Helvetica, sans-serif; font-size:12px; |
2010-10-28 17:06
测试页面代码如下:
<title>加载js以及是否生效测试</title>
<link rel="stylesheet" href="http://www.zhangxinxu.com/study/css/zxx.lib.css" type="text/css" />
<style>
body{font-size:84%;}
a{color:#34538b;}
.linkOn{background:#486aaa; color:#fff;}
</style>
<input id="testText" type="text" /><button id="loadBtn">加载列表</button>
<div id="lo |
2010-10-27 16:41
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mootools动画使用学习与测试</title>
<link rel="stylesheet" href="http://www.zhangxinxu.com/study/css/zxx. |
2010-10-14 16:37
max-width貌似比width对宽度的影响更大。
如下示例:
<style>
img{max-width:400px;}
</style>
<body>
<img src="http://image.zhangxinxu.com/image/study/s/s512/mm1.jpg" width="512" style="width:512px;" />
</body>
结果图片显示的尺寸时400像素,如下图所示:
|
2010-09-20 17:32
如下CSS代码:
<style type="text/css">
.h1{padding-top:1px; background:#ccc;}
.h2{padding-top:1px; background:#ccc; overflow:hidden;}
</style>
如下HTML代码:
<div class="h1"></div>
<div class="h2"></div>
结果在IE7浏览器下:
|
2010-09-16 17:47
代码如下:
document.onclick = function(e){
var e = e || event;
if(e.srcElement){
oTarget = e.srcElement
}else{
oTarget = e.target;
}
alert(oTarget.nodeName.toLowerCase());
};
有不错的兼容性。
(完) |
2010-09-13 16:11
代码如下:
<?php
$test_str = 'Squid can also route content requests to servers in a wide variety of ways to build cache server hierarchies which optimise network throughput.';
$test_arr = explode(' ', $test_str);
while(list($key, $value) = each($test_arr)){
echo $key.': '.$value.'<br />';
}
reset($test_arr);
$new_str = join('|', $test_arr);
echo '<p class="red">'.$new_str.'</p>';
?>
结果如下图: |
2010-09-13 15:05
nl2br()函数将字符串作为输入参数,用HTML中的<br />标记代替字符串中的换行符。
如下实例:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>nl2br使用举例</title>
<link rel="stylesheet" href="http://www.zhangxinxu.com/study/css/zxx.lib.css" type="text/css" />
<?php
if(isset($_POST[ |
2010-09-10 15:01
php代码如下:
<?php
$out = `dir c:`;
echo '<pre>'.$out.'</pre>';
?>
结果如下图:
执行操作符实际上是一对操作符,它是一对反向单引号(``)。php将试着将反向单引号之间的命令当作服务器端的命令来执行。
(完) |
2010-09-10 14:47
代码如下:
<?php
if('hi'){
echo 'hi is true';
}else{
echo 'hi is false';
}
echo '<br />';
if(''){
echo '空字符串 is true';
}else{
echo '空字符串 is false';
}
echo '<br />';
if($test){
echo '$test is true';
}else{
echo '$test is false';
}
?>
结果:
|
|
|
让妻子幸福的
男, 岁
浙江 杭州
|