在项目中用到的一些JS代码

1、禁用页面某些输入框里的右键菜单和Ctrl+V操作

Array.prototype.each=function (iterator){
    
for(var i=0;i<this.length;i++
){
        
try
{
            iterator(
this
[i]);
        }
        
catch
(e){
            
        }
    }
}

var Inputs=document.getElementsByTagName("input"
);
var activeEleFlag=null
;
Inputs.each
=
Array.prototype.each;

Inputs.each(
function
(r){
    
if(!document.all&&r.getAttribute("pasteFlag")!="true"
){
        r.addEventListener(
"focus",function(){activeEleFlag=this.tagName;},false
);
        r.addEventListener(
"blur",function(){activeEleFlag=null;},false
);
    }
});

document.onkeydown
=function
(e){
    
var event=window.event||
e;
    
if(event.ctrlKey&&String.fromCharCode(event.keyCode).toLowerCase()=="v"
){
        
if
(document.activeElement){
            
var activeEle=
document.activeElement;
            
if(activeEle.tagName.toLowerCase()=="input"&&activeEle.getAttribute("pasteFlag")!="true"
){
                event.returnValue
=false
;
                event.cancelBubble
=true
;
                
return false
;
            }
        }
        
else if(activeEleFlag!=null&&activeEleFlag.toLowerCase()=="input"
){
            event.cancelBubble
=true
;
            
if
(event.preventDefault){ 
                event.preventDefault();
            }
            
return false
;
        }
    }
}

 

2、变换页面字体大小

function  ChangeFontSize(fontsize){
    
var fontPara=document.getElementById('content'
);    
    
if
(fontPara){
        fontPara.style.fontSize
=fontsize+'px'
;    
        
if(fontsize==14
){
        
var spanTags=document.getElementById('newsList').getElementsByTagName('span'
);
            
for(iSpan in
 spanTags)
            
if(spanTags[iSpan].className=="lidate")spanTags[iSpan].style.fontSize="10px"
;
        }
        
if(fontsize==10
){
            
var liTags=document.getElementById('newsList').getElementsByTagName('li'
);
            
for(i=0 ;i<liTags.length;i++
){
                liTags[i].style.lineHeight
="180%"
;    
            }
        }
    }
}

 

3、一段插入Flash代码的JS代码

function  i(ur,w,h){
        document.write(
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'"> '
);
        document.write(
'<param name="movie" value="' + ur + '">'
);
        document.write(
'<param name="quality" value="high"> '
);
        document.write(
'<param name="wmode" value="transparent"> '
);
        document.write(
'<param name="wmode" value="opaque"> '
);
        document.write(
'<param name="menu" value="false"> '
);
        document.write(
'<embed src="' + ur + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"  wmode="transparent"></embed> '
);
        document.write(
'</object> '
);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值