在项目中用到的一些JS代码
来源:互联网 发布:你们啊naive 知乎 编辑:程序博客网 时间:2024/04/28 23:49
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;
}
}
}
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%";
}
}
}
}
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> ');
}
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> ');
}
- 在项目中用到的一些JS代码
- 我在项目中用到的一些工具类
- js中用到的一些属性方法
- 项目中用到的一些开源
- 项目中用到mobiscroll的一些心得
- 工作中用到的一些代码
- 项目中用的一些js 等
- js一个项目中用到的脚本
- 项目中用到的js日期函数
- 项目中用到的js日期函数
- 项目中用到的Android代码整理
- 几个项目中用到的代码片段
- 一些我在做项目过程中用到的比较重要的方法
- js: 项目中用到的一个formvalidator的js方法()
- 项目中用到的
- 最近项目中用到sql的一些资料总结
- 《摘*》项目中用到的一些正则,备忘
- 项目中用到的一些第三方库
- apache 2.2.2 + PHP5.1.4 不能运行的解决办法.
- Flex Data Services 2 简介
- linux使用笔记
- 活用NET命令 网络检查如虎添翼
- C#操作Excel帮助
- 在项目中用到的一些JS代码
- 温故知新:回顾ASP商业模式,思考服务计算商业模式
- PHP:我的迷茫和信心
- 老祖宗的遗产与流行时尚:蓬荜生辉
- Frameset中引入的第三方asp.net页面丢session的问题
- 微软的霸气
- 学习使用Makefile
- 弹窗代码全集
- extjs和struts、json的整合 - taelons的专栏 - CSDNBlog