87,904
社区成员
发帖
与我相关
我的任务
分享
//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
$(domChunk).click(function(){
var t = this.title || this.name || null;
var a = this.href || this.alt;
var g = this.rel || false;
tb_show(t,a,g);
this.blur();
return false;
});
}
[<a href="javascript:void(0)" class="preview">预览</a>]
var aLink = document.getElementsByTagName('a');
var nLinkCount = aLink.length;
for (var i = 0; i < nLinkCount; ++i) {
if (aLink[i].className == 'preview') {
aLink[i].onclick = function() {
ajax_request('share_action.php?action=preview', function() {
try {
eval('var oRet = ' + arguments[0].responseText + ';');//返回的参数
share_create_iframe('preview_qq_share', g_sMengluInterfaceUrl + '?action=preview&time=' + oRet.time + '&token=' + oRet.token);
}catch(e) {
alert('预览失败');
}
}
);
return false;
}
}
}
function ajax_request(sServerUrl, fnCallback, bSync, oPostParam, vCallbackParam) {
var oHttpRequest = new window.XMLHttpRequest();
if (!bSync) { //确定是同步还是异步
_set_onreadystatechange(oHttpRequest, fnCallback, vCallbackParam);
}
if (oPostParam) { //处理post方法所传递的参数 形式以&&&累加
var a = [];
for (var s in oPostParam) {
a.push(s + '=' + oPostParam[s]);
}
var sPostParam = a.join('&');
} else {
var sPostParam = null;
}
oHttpRequest.open(sPostParam ? 'post' : 'get', sServerUrl, !bSync);//post 非异步
oHttpRequest.setRequestHeader('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT');
if (sPostParam) {
oHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
oHttpRequest.setRequestHeader('Content-Length', sPostParam.length);
}
oHttpRequest.send(sPostParam);
if (bSync && typeof fnCallback == 'function') {
fnCallback(oHttpRequest, vCallbackParam); //执行post方法返回的数
}
}