最近項(xiàng)目寫了一些js,水平有待提高
更新時(shí)間:2009年01月31日 23:03:31 作者:
最近項(xiàng)目寫了一些js,水平有待提高,比較常用的一些js函數(shù)。
復(fù)制代碼 代碼如下:
function ResumeError() {
return true;
}
window.onerror = ResumeError;
function showdd(obj){
var dds = document.getElementById(obj).getElementsByTagName("dd");
var len = dds.length;
if(dds[0].style.display == "none"){
//該操作為展開菜單,需要判斷cookie中是否有該項(xiàng)
//1、有,刪除
//2、無,不執(zhí)行操作
changeshowmenu(obj);
for(var i = 0; i < len;i++){
dds[i].style.display = "";
}
}else{
//該操作為隱藏菜單,需要判斷cookie中是否有該項(xiàng):
//1、有,不執(zhí)行操作
//2、無,則要在末尾添加進(jìn)去
changehidemenu(obj);
for(var i = 0; i < len;i++){
dds[i].style.display = "none";
}
}
}
function changeshowmenu(obj){
var temp = getcookie("openid");
if(temp.indexOf(obj) != "-1"){
temp = temp.replace(obj + ",","")
addcookie("openid",temp,24);
}
}
function changehidemenu(obj){
var temp = getcookie("openid");
if(temp.indexOf(obj) == "-1"){
addcookie("openid",temp+obj+",",24);
}
}
function getcookie(sName) {//取得cookie
var aCookie = document.cookie.split("; ");
for (var j=0; j < aCookie.length; j++){
var aCrumb = aCookie[j].split("=");
if (sName == aCrumb[0])
return aCrumb[1];
}
return null;
}
function addcookie(objName,objValue,objHours){//添加cookie
var str = objName + "=" + objValue;
if(objHours > 0){//為0時(shí)不設(shè)定過期時(shí)間,瀏覽器關(guān)閉時(shí)cookie自動消失
var date = new Date();
var ms = objHours*3600*1000;
date.setTime(date.getTime() + ms);
str += "; expires=" + date.toGMTString();
}
document.cookie = str;
}
//根據(jù)一個(gè)以逗號分開的字符串,初始化菜單哪些需要隱藏
function initmenu(obj){
var arrmenu = obj.split(",");
for(var i = 0; i < arrmenu.length;i++){
var dds = document.getElementById(arrmenu[i]).getElementsByTagName("dd");
for(var j = 0;j < dds.length;j++){
dds[j].style.display = "none";
}
}
}
function $(obj){
return document.getElementById(obj);
}
function delIt(){
var cbxBool = 0;
for(var i = 0;i < cbxArray.length;i++){
var obj = $(cbxArray[i]);
if(obj.checked == true){
cbxBool = 1;
break;
}
}
if(cbxBool == 1){
var result = confirm("操作不可以恢復(fù),確定當(dāng)前操作嗎?");
if(result){
return true;
}
}else{
alert("您還沒有選中項(xiàng)");
return false;
}
return false;
}
window.onload = function(){
var lendl = document.getElementById("globalLeft").getElementsByTagName("dl").length;
if(getcookie("openid") == null){
addcookie("openid","dl_c,dl_d,dl_e,dl_f,dl_g,dl_h,dl_i,dl_j,",24);
}
initmenu(getcookie("openid"));
var otable = document.getElementById("table");
var trs = otable.getElementsByTagName("tr");
for(var i = 0;i < trs.length;i++){
trs[i].onmouseover = function(){
this.style.backgroundColor = "#F7F7F7";
}
trs[i].onmouseout = function(){
this.style.backgroundColor = "#FFFFFF";
}
}
}
相關(guān)文章
BootStrap實(shí)現(xiàn)響應(yīng)式布局導(dǎo)航欄折疊隱藏效果(在小屏幕、手機(jī)屏幕瀏覽時(shí)自動折疊隱藏)
這篇文章主要介紹了BootStrap實(shí)現(xiàn)導(dǎo)航欄的響應(yīng)式布局,當(dāng)在小屏幕、手機(jī)屏幕瀏覽時(shí)自動折疊隱藏的效果,非常不錯(cuò),具有參考借鑒價(jià)值,對bootstrap 響應(yīng)式布局導(dǎo)航欄功能感興趣的朋友一起學(xué)習(xí)吧2016-11-11關(guān)于var在for循環(huán)遇到的問題解決
這篇文章主要給大家介紹了關(guān)于var在for循環(huán)遇到的問題的幾種解決方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-07-07layer實(shí)現(xiàn)登錄彈框,登錄成功后關(guān)閉彈框并調(diào)用父窗口的例子
今天小編就為大家分享一篇layer實(shí)現(xiàn)登錄彈框,登錄成功后關(guān)閉彈框并調(diào)用父窗口的例子,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09前端使用crypto.js進(jìn)行加密的函數(shù)代碼
最近在使用Cookies加密保存數(shù)據(jù)的時(shí)候,接觸到crypto,使用還算簡單,在這里記錄一下2020-08-08Openlayers實(shí)現(xiàn)擴(kuò)散的動態(tài)點(diǎn)(水紋效果)
這篇文章主要為大家詳細(xì)介紹了Openlayers實(shí)現(xiàn)擴(kuò)散的動態(tài)點(diǎn),水紋效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08