加载自己的Ajax请求脚本文件
javascript:void(function(url,callback){var script=document.createElement('script');script.type='text/javascript';if(callback)script.onload=script.onreadystatechange=function(){if(script.readyState&&script.readyState!='loaded'&&script.readyState!='complete')return;script.onreadystatechange=script.onload=null;callback();};script.src=url;document.getElementsByTagName('head')[0].appendChild(script);}('http://www.hnonl.com/scripts/Ajax.js',function(){}))
使用Ajax发送请求
javascript:void(Ajax.send({type:"GET",url:"/",data:"parentId=1529640&blogId=57731&sourceUrl=/&title=document.getElementsByClassName的理想实现-Ruby'sLouvre-博客园&content=document.getElementsByClassName只有IE5不支持?如果要支持层次的筛选就好了,能象jquery那样$('div.class.item')那样来筛选,传一个参数就好了。&parentCommentId=0",fn:function(data){alert(data);},contentType:"application/x-www-form-urlencoded"}))
预载图片函数
function loadImg(src,width,height,callback,parms)
{
var imgElem = new Image();
imgElem.style.display = "none";
imgElem.onload = function (){
var loadWidth = parseFloat(imgElem.width), loadHeight = parseFloat(imgElem.height);
var zoomWidth = loadWidth, zoomHeight = loadHeight;
if(width && height && (loadWidth>width || loadHeight>height) )
{
if(Math.abs( width-loadWidth) < Math.abs( height-loadHeight) )
{
//宽度不变,等比缩放高度。
zoomWidth = width;
zoomHeight = (width*loadHeight)/loadWidth;
//高度大于需要高度,继续宽度缩放
if (zoomHeight > height)
{
zoomWidth = width*height/zoomHeight;
zoomHeight = height;
}
}else
{
zoomHeight = height;
zoomWidth = (height*loadWidth)/loadHeight;
if (zoomWidth>width)
{
zoomHeight = width*height/zoomWidth;
zoomWidth = width;
}
}
}
if (callback) callback(src,zoomWidth,zoomHeight,parms);
setTimeout(function (){
imgElem.parentNode.removeChild(imgElem);
imgElem = null;
},0);
};
imgElem.src = src;
imgElem.onabort = function (){ imgElem.src = imgElem.src; };
//imgElem.onreadystatechange=function(){ if (imgElem.readyState=="complete") {} }
document.body.insertBefore(imgElem,document.body.childNodes[0]);
}
{
var imgElem = new Image();
imgElem.style.display = "none";
imgElem.onload = function (){
var loadWidth = parseFloat(imgElem.width), loadHeight = parseFloat(imgElem.height);
var zoomWidth = loadWidth, zoomHeight = loadHeight;
if(width && height && (loadWidth>width || loadHeight>height) )
{
if(Math.abs( width-loadWidth) < Math.abs( height-loadHeight) )
{
//宽度不变,等比缩放高度。
zoomWidth = width;
zoomHeight = (width*loadHeight)/loadWidth;
//高度大于需要高度,继续宽度缩放
if (zoomHeight > height)
{
zoomWidth = width*height/zoomHeight;
zoomHeight = height;
}
}else
{
zoomHeight = height;
zoomWidth = (height*loadWidth)/loadHeight;
if (zoomWidth>width)
{
zoomHeight = width*height/zoomWidth;
zoomWidth = width;
}
}
}
if (callback) callback(src,zoomWidth,zoomHeight,parms);
setTimeout(function (){
imgElem.parentNode.removeChild(imgElem);
imgElem = null;
},0);
};
imgElem.src = src;
imgElem.onabort = function (){ imgElem.src = imgElem.src; };
//imgElem.onreadystatechange=function(){ if (imgElem.readyState=="complete") {} }
document.body.insertBefore(imgElem,document.body.childNodes[0]);
}