📄 function.js
字号:
//作用:全选
//参数:元素类型,要复选的元素名称
function selectAllCheckBox(objName,selfObjName){
var coll = document.getElementsByTagName('input')
if(!coll) return;
if(coll.length){
for(var i = 0;i < coll.length;i++){
if (coll.item(i).name == objName) coll.item(i).checked = document.getElementById(selfObjName).checked;
}
}else{
coll.checked = document.getElementById(selfObjName).checked;
}
}
//作用:获取列表值
//参数:元素类型
function getValueList(tagName){
var result = "";
var coll = document.getElementsByTagName(tagName)
if(!coll) return result;
if(coll.length){
for(var i = 0;i<coll.length;i++){
if(coll.item(i).checked){
result += (result == "")?coll.item(i).value:("," + coll.item(i).value);
}
}
}else{
if(coll.checked){
result = coll.value;
}
}
return result;
}
//作用:获取资源值,用半角逗号[,]分隔
//参数:对象,值
function getItemValue(tagName,val) {
if (val == ''){
document.getElementById(tagName).value = '';
}
else {
if (document.getElementById(tagName).value == ''){
document.getElementById(tagName).value = val;
}
else {
document.getElementById(tagName).value = document.getElementById(tagName).value +','+ val;
}
}
}
//作用:验证按钮是否Disabled
//参数:条件(为空/非空)
function checkDisabled(tagName,objNull) {
var coll = document.getElementsByTagName('input')
var temp = false;
if (objNull == '') temp = true;
if (!coll) return;
if (coll.length){
for(var i = 0;i < coll.length;i++){
if (coll.item(i).name == tagName) coll.item(i).disabled = temp;
}
}else{
coll.disabled = temp;
}
}
//作用:菜单点击后样式切换
//参数:对象
function menuStyle(objName,tag){
var coll = document.getElementsByTagName('span')
if(!coll) return;
if(coll.length){
for(var i = 0;i < coll.length;i++){
if (coll.item(i).id == objName){
if (tag == 'top'){
coll.item(i).className = 'clickedtop';
}
else {
coll.item(i).className = 'clickedmenu';
}
}
else {
if (tag == 'top'){
coll.item(i).className = '';
}
else {
coll.item(i).className = 'menu';
}
}
}
}
}
//作用:生成随机字符串
//参数:长度,类型
function randomChar(l,t){
if (t == 1){
var x = "0123456789poiuytrewqasdfghjklmnbvcxzQWERTYUIOPLKJHGFDSAZXCVBNM";
}else{
var x = "0123456789ABCDEF";
}
var tmp = "";
for(var i = 0;i < l;i ++) {
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
}
return tmp;
}
//作用:显示/隐藏制定对象
//参数:对象ID
function showTr(id) {
if (document.getElementById(id).style.display == 'none'){
document.getElementById(id).style.display = ''
}else {
document.getElementById(id).style.display = 'none'
}
}
//作用:切换前后两张图片
//参数:关闭的图,展开的图,对象id
function changePic(pic1,pic2,id) {
if (document.getElementById(id).title == '点击展开') {
document.getElementById(id).src = pic2;
document.getElementById(id).title = '点击合起';
}
else {
document.getElementById(id).src = pic1;
document.getElementById(id).title = '点击展开';
}
}
//作用:弹出窗口
//参数:窗口地址
function openSelWin(url,winWidth,winHeight) {
var regWin = window.open(url,'selWin','modal=yes,toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=no,width='+ winWidth +',height='+ winHeight);
if (regWin) {
regWin.moveTo((screen.availWidth - winWidth) / 2,(screen.availHeight - winHeight - 12) / 2);
regWin.focus();
}
return true;
}
//作用:获取点击数
//参数:
function getClickNum(virtualRoot,oprateTable,key,PublicID,tagObj,updateTF) {
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=click&table='+ oprateTable +'&key='+ key +'&id='+ PublicID +'&updateTF='+ updateTF,0,0,tagObj)
}
//作用:获取回复数
function getReNum(virtualRoot,PublicID,tagObj) {
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=getReviewNum&id='+ PublicID,0,0,tagObj)
}
//作用:验证帖子内容
function CheckReviewLength(tag,maxLength) {
var a = GetLength(tag);
if (a == 0) {
alert('1、帖子内容不能为空\n2、请不要使用纯表情或纯图片作为帖子内容');
return false;
}
else if (a > maxLength) {
alert('帖子内容超出字数限制');
return false;
}
else {
return true;
}
}
//作用:搜索提交
function SearchSubmit(virtualRoot) {
var key = document.getElementById('keyword').value;
if (key == ''){
alert('请输入关键字');
}
else {
location.href = virtualRoot +'/Lib/Search.shtml?page=1&key='+ escape(key);
}
}
/**********************会员相关操作***********************/
//验证会员阅读权限
function CheckReadGroup(virtualRoot,readscore,infoId,pageNo) {
var userRead = xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=getUserReadGroup&id='+ infoId +'&readscore='+ readscore,0,2,'');
if (userRead == 'True'){
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=checkReadGroup&id='+ infoId +'&pageNo='+ pageNo,0,0,'Info_'+ infoId);
}
}
//验证用户是否登录
function GetUserLoginForm(virtualRoot,action,tempId,formId) {
if (UserOnline(virtualRoot,formId)){
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=onlineTime',0,0,'');
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=showUserInfo',0,0,'LoginForm_'+ formId);
}
else {
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action='+ action +'&tempid='+ tempId +'&id='+ formId,0,0,'LoginForm_'+ formId);
}
}
//定时统计用户信息
function UserOnline(virtualRoot,formId) {
var userLogin = xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=checkUser',0,2,'');
if (userLogin == 'True'){
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=onlineTime',0,0,'');
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=showUserInfo',0,0,'LoginForm_'+ formId);
return true;
}
else {
return false;
}
}
//用户退出
function userLogout(virtualRoot) {
if (confirm('是否真的要退出?')){
xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=userLogout',0,0,'');
location.reload();
}
}
//验证登录
function ChkUserLogin(virtualRoot,action,formId) {
var errCode = '';
var saveCookie = '';
var cookieSave = '';
var tempid = document.getElementById('tempId').value;
var usn = document.getElementById('usn').value;
var psw = document.getElementById('psw').value;
var code = document.getElementById('code').value;
var saveCookie = document.getElementById('savecookie').checked;
if (saveCookie) cookieSave = 1;
if (usn == ''){
errCode = errCode +'用户名不能为空\n';
}
if (psw == ''){
errCode = errCode +'密码不能为空\n';
}
if (code == ''){
errCode = errCode +'验证码不能为空';
}
if (errCode != ''){
alert('错误提示:\n\n'+ errCode);
}
else {
var a = xmlHttpPost(virtualRoot +'/Lib/XmlHttp.asp','action=checkUserLogin&tempid='+ tempid +'&usn='+ usn +'&psw='+ psw +'&code='+ code +'&savecookie='+ cookieSave +'&id='+ formId,0,2,'LoginForm_'+ formId);
if (a == '0'){
location.reload();
}
else {
document.getElementById('LoginForm_'+ formId).innerHTML = a;
}
}
}
//作用:显示评论
function getReview(virtualRoot,reviewType,PublicID,pageNo,tempId,showType) {
if (showType == 'List') {
xmlHttpPost(virtualRoot +'/Lib/xmlHttp.asp','action=getReviewList&id='+ PublicID +'&reviewType='+ reviewType +'&pageNo='+ pageNo +'&tempid='+ tempId,0,0,'P_'+ PublicID);
}
}
/**********************会员相关操作***********************/
/**********************翻页操作***********************/
//作用:信息块分页跳转
//参数:总页数,目标页码,位置,目标对象前缀,附加传递参数
function changePage(virtualRoot,action,pCount,pButton,pPlace,pType,tagObj,condition) {
var pNo = '';
if (pButton == 'First'){
pNo = 1;
}
else if (pButton == 'Previous'){
if (document.getElementById('P_'+ tagObj +'_No0')) pNo = Number(document.getElementById('P_'+ tagObj +'_No0').innerHTML) - 1;
if (document.getElementById('P_'+ tagObj +'_No1')) pNo = Number(document.getElementById('P_'+ tagObj +'_No1').innerHTML) - 1;
if (pNo < 1) pNo = 1
}
else if (pButton == 'Next'){
if (document.getElementById('P_'+ tagObj +'_No0')) pNo = Number(document.getElementById('P_'+ tagObj +'_No0').innerHTML) + 1;
if (document.getElementById('P_'+ tagObj +'_No1')) pNo = Number(document.getElementById('P_'+ tagObj +'_No1').innerHTML) + 1;
if (pNo > pCount) pNo = pCount
}
else if (pButton == 'Last'){
pNo = pCount;
}
else {
pNo = Number(pButton);
}
if (pType == 0){
for (var i = 1;i <= pCount;i ++ ){
if (i == pNo) document.getElementById('P_'+ tagObj +'_'+ i).style.display = '';
else document.getElementById('P_'+ tagObj +'_'+ i).style.display = 'none';
}
}
else {
xmlHttpPost(virtualRoot +'/Lib/xmlHttp.asp','action='+ action +'&id='+ tagObj +'&page='+ pNo +'&condition='+ condition,0,0,'P_'+ tagObj)
}
if (document.getElementById('P_'+ tagObj +'_No0')) document.getElementById('P_'+ tagObj +'_No0').innerHTML = pNo;
if (document.getElementById('P_'+ tagObj +'_No1')) document.getElementById('P_'+ tagObj +'_No1').innerHTML = pNo;
}
/**********************翻页操作***********************/
//作用:xmlHttp应用
//参数:要接收的URL,传递的值,传递类型(0.POST/1.GET),处理方式(0.输出到对象/1.传递给对象值/2.返回值),返回的ID
function xmlHttpPost(url,valueStr,postType,oprateType,id)
{
if (oprateType == 0) {
if (document.getElementById(id)) document.getElementById(id).innerHTML = val;
}
xmlhttp = false;
var postStr = 'POST';
if (postType == 1) {
postStr = 'GET'
}
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType('text/xml');
}
}else if (window.ActiveXObject) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -